Wednesday, February 15, 2023

Print Column Until End of Line in Linux Terminal

I have a document named mydoc.txt which contains below lines

local STAFF
local STUDENTS
local CONTRACT TEACHERS

I need to print all except the first column. To accomplish that, I can use this command
$ cut -f2- -d ' ' mydoc.txt

Where -d is delimiter, and -f is field number. The hyphen after -f2 is to tell 'cut' to print field number 2 until the end of line.

Wednesday, February 8, 2023

Remove Defunct (Zombie) Process Linked to Cinnamon in Linux Mint

I encountered this situation before, whereby my Linux Mint (cinnamon) is showing that it has 20 zombie processes, linked to the cinnamon process as parent process.


How to check for zombie processes?
$ ps -ef | grep defunct

Or you can run top, and view the second line for "zombie" keyword
$ top
To exit from top, just press q

Calculate how many zombie processes inside a system
$ ps -ef | grep defunct | grep -v grep | wc -l

One of the way to remove zombie processes is to restart the parent process. How to check which is the parent process of the zombie processes?
$ ps -ef | grep defunct | awk '{print $3}'

Once we get the PID of the parent process, check what is the actual process that is using the PID
$ ps -ef | grep <PIDNUMBER>

For example, if the PID number is 2323
$ ps -ef | grep 2323

Once we know what is the process, we can safely restart the parent process. 
In the case of cinnamon, a restart can be accomplished by simply pressing ctrl + alt + esc. 

If that is not working, kill the cinnamon PID first, then do ctrl + alt + esc.
$ kill 2323

Your desktop will freeze after you kill cinnamon, but you can restart it by pressing ctrl + alt +esc.