- Unix Commands Reference
- Unix Commands - Home
kill command in Linux with Examples
Name
kill - send a signal to a process
Synopsis
kill [options] <pid> [...] kill [-l | --list | -t | --table] [SIGNAL]...
Description
kill command sends a signal to processes, causing them to terminate. It is normally a shell builtin meaning the command is called from a users shell rather than an external executable program. The first form of the kill command sends a signal to all PID arguments. The default signal for kill command is TERM signal (terminate an active process). On specifying a particular SIGNAL (name or number), the process acts upon receiving the signal in a specified way.
Alternatively, kill command can list information about types of available signals. Use -l or -L to list all available signals. Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0. Signals may be specified in three ways: -9, -SIGKILL or -KILL.
Negative PID values may be used to choose whole process groups; see the PGID column in ps command output. A PID of -1 is special; it indicates all processes except the kill process itself and init.
Options
<pid> [...] Send signal to every <pid> listed. -<signal> -s <signal> --signal <signal> Specify the signal to be sent. The signal can be specified by using name or number. The behavior of signals is explained in signal(7) manual page. -l, --list [signal] List signal names. This option has optional argument, which will convert signal number to signal name, or other way round. -L, --table List signal names in a nice table. NOTES: Your shell (command line interpreter) may have a built-in kill command. You may need to run the command described here as /bin/kill to solve the conflict.
Examples
1. Send the default signal, SIGTERM, to all those processes.
$ kill 20539 20549 20559 20720
2. Kill all the processes you can kill.
$ kill -9 -1
3. Translate signal number 11 into a signal name.
$ kill -l 11 SEGV $ kill -l 6 ABRT
4. To view signal names and numbers pass the -l option to the kill command.
$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
5. There is a special signal number ‘0’. It does not denote a valid signal, but it can be used to test whether the PID arguments specify valid processes to which a signal could be sent.
$ ps PID TTY TIME CMD 11571 pts/20 00:00:00 bash 22166 pts/20 00:00:00 ps
6. Here 11571 is a valid PID. When a signal 0 is sent to this process, kill command exits with an exit status 0. While when the same 0 signal is sent to a non-existent PID like 11579, it reports that there is no such process currently in the system.
$ kill -s 0 11571 $ kill -s 0 11579 bash: kill: (11579) - No such process
If PID is positive, the signal is sent to the process with the process ID PID. If PID is zero, the signal is sent to all processes in the process group of the current process. If PID is −1, the signal is sent to all processes for which the user has permission to send a signal. If PID is less than −1, the signal is sent to all processes in the process group that equals the absolute value of PID.