Different commands are used to send signals to processes to terminate or “kill” them. This is necessary when a process becomes unresponsive (hangs), causes system instability, or fails to relinquish control over a file you’re trying to modify.
The “kill” command sends any specified signal, or by default the termination signal, to one or more processes. The PID must be specified as the argument.
The following are some examples of implementing kill signals. To terminate a process with ID 921 gracefully:
# kill 15 921
Failing that, to kill the process immediately:
# kill 9 921
Alternatively, to pause rather than remove the process entirely:
# kill 17 921
If you encounter the below error while running the kill command:
kill: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
Debian | apt-get install procps |
Ubuntu | apt-get install procps |
Alpine | apk add procps |
Arch Linux | pacman -S procps-ng |
Kali Linux | apt-get install procps |
CentOS | yum install procps-ng |
Fedora | dnf install procps-ng |
Raspbian | apt-get install procps |
kill Command Examples
1. To get the list of signals:
# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE 9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGURG 17) SIGSTOP 18) SIGTSTP 19) SIGCONT 20) SIGCHLD 21) SIGTTIN 22) SIGTTOU 23) SIGIO 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGINFO 30) SIGUSR1 31) SIGUSR2
2. To send a particular signal:
# kill -s 9
3. To specify the list of processes for kill:
# kill 1234 2345 3456
4. Terminate a program using the default SIGTERM (terminate) signal:
# kill process_id
5. Terminate a background job:
# kill %job_id
6. Terminate a program using the SIGHUP (hang up) signal. Many daemons will reload instead of terminating:
# kill -1|HUP process_id
7. Terminate a program using the SIGINT (interrupt) signal. This is typically initiated by the user pressing `Ctrl + C`:
# kill -2|INT process_id
8. Signal the operating system to immediately terminate a program (which gets no chance to capture the signal):
# kill -9|KILL process_id
9. Signal the operating system to pause a program until a SIGCONT (“continue”) signal is received:
# kill -17|STOP process_id
10. Send a `SIGUSR1` signal to all processes with the given GID (group id):
# kill -SIGUSR1 -group_id