Ubuntu – How To Kill Process By PID Or Name

Kill Linux processes or unresponsive applications in Linux using “Kill” command. Kill Linux process by name or PID. How to use Linux Kill command. Tutorial on Kill command in Linux Ubuntu with example.

Kill command can be used to kill or terminate a process using “Signal” or “PID.” The command kill sends the specified signal to the specified processes or process groups. If no signal is specified, the TERM signal is sent. This TERM signal will kill processes that do not catch it; for other processes it may be necessary to use the KILL signal (number 9), since this signal cannot be caught.

 

kill-man-ubuntu-01

For a kill command a Signal Name could be any of the following:

Signal Name Signal Value Behaviour

SIGHUP 1 Hangup
SIGKILL 9 Kill Signal
SIGTERM 15 Terminate

The SIGTERM is the default and safest way to kill a process as it terminates the process.

kill -9 -1 Kill all processes you can kill.

Below is the format of the Kill command:

kill [ -signal | -s signal ] pid …

The most easiest way to kill a process is to find the PID of the resource and then run the PID as arguement with the kill command.

What is a PID?

Each Linux or Unix process or a running program is automatically assigned a unique process identification number (PID). A PID is automatically assigned number to each process on the system.

you can find PID of a resource using the “pidof” or “ps” command. To find out PID of a process (say firefox), use the following command:


pidof firefox

You can also use the command in other form:


ps -A | grep -i firefox

 

PID-Ubuntu-03

In the above output, the number “2393” is the PID of process of firefox. Once the PID of a process (firefox) is known, you can use the kill command to kill the process (firefox) as shown below.


kill 2393

When the kill command is executed, it sends a signal to a process whose PID is passed along with the command as argument.

To be more specific, the Kill command has the following forms:

kill [signal] PID
kill -15 PID
kill -9 PID
kill -SIGTERM PID
kill [options] -SIGTERM PID

 

kill-example

The Kill command has the following return codes:

  • 0 success
  • 1 failure
  • 64 partial success (when more than one process specified)

Please note that there are few rules to use Kill command:

  • You can kill all your own process.
  • Only root user can kill system level process or process started by other users.

For X server, there is another command called xkill which can kill a process. The xkill command runs from its X window without passing process name or its PID.

Related Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.