KILL command in Linux
Here’s how to use the KILL command within Linux
$ KILL [options] <PID>
Linux KILL options:
Option | Description |
---|---|
-s | Specify what kill signal to send. |
-l | Shows the name of the signal through the signal number. |
-L | List all the available signals. |
q | Sends the signal using sigqueue(3) instead of kill(2), allowing an additional integer value to be sent along with the signal. |
Here are the common signal to use within the KILL command
Signal Number | Signal Name | Description |
---|---|---|
1 | SIGHUP | Re-read configuration (like reloading web server settings). |
2 | SIGINT | Interrupt the process, similar to pressing Ctrl+C . |
3 | SIGQUIT | Quit and create a core dump (for debugging crashes). |
9 | SIGKILL | Forcefully terminate immediately (use with caution!). |
15 | SIGTERM | Politely request termination, allowing for cleanup (default). |
Example of the KILL COMMAND
- List Available Signal
To list all available signal, simply use the -L option:
$ kill -L
ubuntu@student:~$ 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
2. Kill a process using the kill command
to kill a process we need to know the <PID> or the process id. For that we can run the command below:
pidof <process_name>
Example: $ pidof nginx
1443 1442 1441 1440 1376
After we know the pid of which process we would like to kill, simply use the kill command. for this example we’re gonna use the signal SIGKILL (9) which kills the child of the processes as well, so use it with cautions
$ kill -9 1440
3. Kill multiple processed at once
To kill multiple processes at once, all you need to do is append multiple processes within one kill command
example:
$ kill -9 1080 1920 2160 1961