How to kill a Process in Linux / UNIX Systems (Terminate Process in Linux)




 

To kill processes in Linux several options can be used.

kill command


The most important and frequently used option is kill command.
The kill command is used to terminate the processes on Linux and several other Unix like systems.
The kill command enables us to kill a process without logging out or restarting the computer.
Each process (also called task sometimes) on Linux  have its own unique process identification number (PID).
The PID is assigned to the process as soon as it is created.

The kill command has following syntax:

kill [options or signals] [...]

The kill command in its simplest for can be as follows:

Where 1565 in the above command is the PID of the process.

The PID of a process can be found in following ways:

Use ps command to find the PID of process
To print all the processes and their corresponding PID, run the following command:

The sample output of the above command can be as follows.

If you know the process name you can get its PID using the grep on ps command.
For example you want to know the PID of process whose name is psql the following command will give you the PID of the psql.

The sample output of the above command can be as follows.

Use pidof command to find the PID of process
For example you want to know the PID of process whose name is psql the following command will give you the PID of the psql.

Output

The following command can be use to kill process based upon PID

or

where pid=1656.
-9 flag in the above command is SIGKILL.
The default signal for kill is SIGTERM.

To kill more then one processes use the following command

or

or

where PID1, PID2, PID3 are the PID of the processes.

To list all the signal names with their corresponding number use following command

Output:

some other examples
kill -9 -1
Kill all processes you can kill.

kill -l 11
Translate number 11 into a signal name.

kill -L
List the available signal choices in a nice table.

kill 123 543 2341 3453
Send the default signal, SIGTERM, to all those processes.

kill -legal
List signal names. This option has optional argument, which will convert signal number to signal
name, or other way round.

killall command


killall cammand can be used to kill processes by their name.

killall syntex:

killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent.
Signals can be specified either by name (e.g. -HUP or -SIGHUP) or by number (e.g. -1) or by option -s.

Example:
For example you want to kill the process whose name is psql. use the following command:

pkill command


pkill command look up or signal processes based on name and other attributes.

syntex
pkill [options] pattern

Example:
Send SIGTERM to all the process which has psql in its name.

before giving the above command we can find which processes are fulfilling the above criteria by following command:

We can find the status of a process by using one of the command below:


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com