DEV Community

Saravanan
Saravanan

Posted on

Process management in GNU/Linux

Kill

Kill is a program that is used to send signals to a process or process groups. By default TERM is sent to the process if no signal is specified. We can send any signal to the process as below

$kill -SIGNAL PID
Enter fullscreen mode Exit fullscreen mode

The signal can be a name or number. the list of signals with number and name is listed with the below command

$kill -l
Enter fullscreen mode Exit fullscreen mode

By default, kill will send SIGTERM or 15 to the process. This will send the signal to the process and it is handled as per the process. It can be blocked, handled, or ignored by the process.

$kill -9 PID
$kill -KILL PID
Enter fullscreen mode Exit fullscreen mode

The above sends SIGKILL causes the process and its child processes to terminate immediately. The process can't block or ignore this.

$kill -HUP PID
Enter fullscreen mode Exit fullscreen mode

The above signal also terminates the program but, the difference is it is sent by the system when a terminal is closed and all the processes started from the terminal will receive SIGHUP which means a hang-up signal.

$kill -STOP PID
Enter fullscreen mode Exit fullscreen mode

The above command sends SIGSTOP to the process which suspends the process immediately. It can then be resumed by sending the SIGCONT signal.

For the most common use, killall is used. It kills a process by its name. For example, to kill chrome below command can be used. The -w flag is to wait till all signaled processes die.

$killall -w chromium-browser
Enter fullscreen mode Exit fullscreen mode

PS - process status

The ps shows which processes are running currently running. There are 3 styles to the arguments for ps. GNU with long names and double dash, BSD usually without any dash, and UNIX with dashes. The below commands are essentially the same

$ps -ef
$ps aux
Enter fullscreen mode Exit fullscreen mode

All default columns are self-explanatory except the STAT which shows the status of the process. The meaning of each letter for this column is given below.

  • R: running
  • Z: zombie
  • D/S: sleep
  • T: stopped
  • N: low priority
  • l: multithreading
  • s: session leader
  • +: foreground process group
  • <: high priority
$ps auxf
$ps auxwww
$ps auxe
Enter fullscreen mode Exit fullscreen mode

The f is forest, which is used to show process trees in ASCII art. www is to expand the width and shows processes with all of its arguments. e will display with environment variables.

TOP

TOP is a cli task manager program. It gives a live update of top users of the system's resources.

$top
Enter fullscreen mode Exit fullscreen mode

The load average with 3 numbers gives average CPU use in the last 1, 5, and 15 minutes. Each column is described below.

  • %CPU: shows percent use of single-core, for the 12-core processor it can be up to 1200%
  • %MEM: use of disk space
  • COMMAND: command line used to start the process
  • RES: the amount of RAM used
  • USER: owner of the process

Top comments (0)