kill is a shell builtin in most Bourne-derived shells such as Bash and Zsh.
KILL(1)NAMEkill — terminate or signal a processSYNOPSISkill [-s signal_name] pid …kill -l [exit_status]kill -signal_name pid …kill -signal_number pid …DESCRIPTIONThe kill utility sends a signal to the processes specified by the pid operands.Only the super-user may send signals to other users’ processes.
It doesn’t give the process a chance to cleanly. Your process may need to:
- Shut down socket connections
- Clean up temp files
- Inform its children that it is going away
- Reset its terminal characteristics
There are many other cleanup cases.
Let’s look at the available options.
0 - ?
1 - SIGHUP - ?, controlling terminal closed,
2 - SIGINT - interupt process stream, ctrl-C
3 - SIGQUIT - like ctrl-C but with a core dump, interuption by error in code, ctl-/
4 - SIGILL
5 - SIGTRAP
6 - SIGABRT
7 - SIGBUS
8 - SIGFPE
9 - SIGKILL - terminate immediately/hard kill, use when 15 doesn't work or when something disasterous might happen if process is allowed to cont., kill -9
10 - SIGUSR1
11 - SIGEGV
12 - SIGUSR2
13 - SIGPIPE
14 - SIGALRM
15 - SIGTERM - terminate whenever/soft kill, typically sends SIGHUP as well?
16 - SIGSTKFLT
17 - SIGCHLD
18 - SIGCONT - Resume process, ctrl-Z (2nd)
19 - SIGSTOP - Pause the process / free command line, ctrl-Z (1st)
20 - SIGTSTP
21 - SIGTTIN
22 - SIGTTOU
23 - SIGURG
24 - SIGXCPU
25 - SIGXFSZ
26 - SIGVTALRM
27 - SIGPROF
28 - SIGWINCH
29 - SIGIO
29 - SIGPOLL
30 - SIGPWR - shutdown, typically from unusual hardware failure
31 - SIGSYS
You got some options, my friend! To kill a process respectfully, you should:
- Try to send a
- After a few seconds, If It is not dead send a
- If It persists send a
What if it doesn’t want to terminate at the end?
- If you are using an external binary and it didn’t stop after all of this, you should probably get rid of it.
- If you are developing a program and can’t get it to stop correctly, you should better handle the killing signals.
Just don’t use