Linux Command - kill
The Linux kill command is used to send signals to processes. The default signal sent is TERM.
You may or may not have more than one version of the kill command on your system. For example, one from the procps-ng package and one that is built into the shell.
Sending the TERM signal to a process will usually kill the process unless that process has logic to catch the signal.
Kill process with PID 123 ( send TERM signal ):
kill 123
Same but for four PIDS:
kill 123 543 2341 3453
Force kill a process ( -9 can’t be caught ):
kill -9 123
Note, when specifying signals by name, don’t include “SIG”:
kill -hup 150746
kill -term 150750
kill -kill 150753
Show a table of signals and signal names:
kill -L
Top 3 signals you should really know for normal sysadmin use:
- 1 SIGHUP (“signal hang up”) means controlling terminal is closed, will cause some daemons will restart and re-read configs
- 9 SIGKILL Kill, terminate immediately, can’t be caught or ignored, proc can’t cleanup, exception procs: zombie, blocked, init, uninterruptibly sleeping
- 15 SIGTERM Request process termination, can be ignored or caught allowing for cleanup, etc.
This list of signal descriptions has been cobbled together from different sources. This is meant to be correct for Linux and may be different for other Unix based systems.
0 | Nothing | No signal sent, still does error checking, checks if proc is running, and often not listed in documentation | |
1 | SIGHUP | Terminate | (“signal hang up”) means controlling terminal is closed, will cause some daemons will restart and re-read configs |
2 | SIGINT | Terminate | Interrupt, causes process to terminate, can be ignored or caught allowing for cleanup, etc. ctrl - c |
3 | SIGQUIT | Terminate (core dump) | Terminate process and create core dump ctrl + \ |
4 | SIGILL | Terminate (core dump) | Sent to a process when it attempts to execute an illegal, malformed, unknown, or privileged instruction. |
5 | SIGTRAP | Terminate (core dump) | Sent to process when trap occurs - debugger wants to be informed of |
6 | SIGABRT | Terminate (core dump) | Tell process to terminate, usually sent by self using abort(), can be from other process |
7 | SIGBUS | Terminate (core dump) | Sent to process when it causes a bus error. example: incorrect memory access alignment or non-existent physical address |
8 | SIGFPE | Terminate (core dump) | Exceptional (but not necessarily erroneous) condition has been detected in the floating point or integer arithmetic hardware. |
9 | SIGKILL | Terminate | Kill, terminate immediately, can’t be caught or ignored, proc can’t cleanup, exception procs: zombie, blocked, init, uninterruptibly sleeping |
10 | SIGUSR1 | Terminate | User defined |
11 | SIGSEGV | Terminate (core dump) | Terminate (core dump) Invalid memory reference - segmentation fault - segmentation violation. |
12 | SIGUSR2 | Terminate | User defined |
13 | SIGPIPE | Terminate | Write on a pipe with no one to read it |
14 | SIGALRM | Terminate | Alarm clock |
15 | SIGTERM | Terminate | Request process termination, can be ignored or caught allowing for cleanup, etc. |
16 | SIGSTKFLT | NA | Coprocessor experiences a stack fault ( NOT ON LINUX ) |
17 | SIGCHLD | Ignore | Sent when child process terminates |
18 | SIGCONT | Continue | Start process back up after it was stopped / paused |
19 | SIGSTOP | Stop | The SIGSTOP signal instructs the operating system to stop a process for later resumption. ( pause ) |
20 | SIGTSTP | Stop | Terminal stop, causes process to suspend execution ctrl - z |
21 | SIGTTIN | Stop | Background process attempting read |
22 | SIGTTOU | Stop | Background process attempting write |
23 | SIGURG | Ignore | Out-of-band data is available at a socket |
24 | SIGXCPU | Terminate (core dump) | CPU time limit exceeded |
25 | SIGXFSZ | Terminate (core dump) | File size limit exceeded |
26 | SIGVTALRM | Terminate | Virtual timer expired |
27 | SIGPROF | Terminate | Profiling timer expired |
28 | SIGWINCH | Ignore | Terminal window size changed |
29 | SIGIO | …. | SIGIO is a signal that is sent when normal data, OOB data, error conditions, or just about anything happens on any type of socket. |
30 | SIGPWR | …. | sent on power failure |
31 | SIGSYS | Terminate (core dump ) | bad argument sent to system call, rare because of libraries |
34 | SIGRTMIN | …. | User defined real time signal |
64 | SIGRTMAX | …. | User defined real time signal |
Listing the signals:
$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
$