How to use the kill command in Linux

Created

kill is a command that is used in several popular operating systems to send signals to running processes.

The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught.

To display all the available signals you can use below command option:

signals
kill -l
Help
man kill
info kill
the process ID
kill -s TERM 1234
kill -TERM 1234
kill -15 1234
kill -s KILL 1234
kill -KILL 1234
kill -9 1234
 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

Terminating Processes Using the kill Command

killing
kill -9 $(pidof chrome)
reload nginx
kill -1 30251
kill

The syntax for the kill command is as follows:

Usage: 
  kill [-s signal|-p] [-q sigval] [-a] [--] pid...
  kill -l [signal]

OPTIONS:
-s, --signal
Specify the signal to send. The signal may be given as a signal name or number.
-p, --pid
Specify that kill should only print the process id (pid) of the named processes, and not send any signals.
-l, --list [signal]
Print a list of signal names, or convert signal given as argument to a name. The signals are found in /usr/include/linux/signal.h
-L, --table
Similar to -l, but will print signal names and their corresponding numbers.
-p, --pid
Specify that kill should only print the process id (pid) of the named processes, and not send any signals.
-q, --queue sigval
Use sigqueue(2) rather than kill(2) and the sigval argument is used to specify an integer to be sent with the signal. If the receiving process has installed a handler for this signal using the SA_SIGINFO flag to sigaction(2), then it can obtain this data via the si_value field of the siginfo_t structure.

Related Tags

#Linux# #kill#