Sooner or later you will find that an errant process is running amok or in the background and it needs to be stopped. This is called killing a process in Linux.
The most common command to kill a process is
- To kill a process, provide its PID:
$ kill 1234
kill sends the
- To kill multiple processes, provides all their PIDs:
$ kill 1234 5678 9999
- Many other signals other than
TERMcan be sent to processes. To list all the available signal numbers and their corresponding signal names:
$ kill -L
- To send a different signal provide the signal name:
$ kill -KILL 1234
- The signal name can also be specified by appending a
$ kill -SIGKILL 1234
- Alternatively, you can provide the signal number:
$ kill -9 1234
- For most processes, sending the default
TERMis enough. Most processes receive this signal, clean up their work and exit. For errant processes which do not respond to
TERM, the final deathblow is sending a
KILL. On sending this signal, the kernel steps in and it directly murders the process giving it no chance to clean up.
Looking up the PID of a process and then killing it is usually cumbersome. What you usually want to do is to kill based on the process name. This can be done using the
- To kill all Vim processes:
$ killall vim
- To kill all processes that match a regex:
$ killall -r "*abcd*"
- By default,
TERMsignal. Other signals can be sent using signal number or signal name using the same command syntax as the
killcommand shown above.
killallonly prints out the processes that it could not kill. It might be better to also see output from the command when it succeeds. The verbose option can be used for this:
$ killall -v vim Killed vim(28952) with signal 15 Killed vim(28347) with signal 15
- You might be afraid that you might kill processes by mistake with this command. If so use the interactive option to pick and choose which process to kill:
$ kill -i vim Kill vim(1067) ? (y/N)
Tried with: Ubuntu 14.04