Bash Man Page: kill <pid> vs kill -9 <pid>
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Bleepage Open
--
Chapters
00:00 Bash Man Page: Kill ≪Pid≫ Vs Kill -9 ≪Pid≫
00:27 Accepted Answer Score 45
01:23 Answer 2 Score 7
01:51 Answer 3 Score 4
03:06 Thank you
--
Full question
https://superuser.com/questions/107543/b...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#unix #bash #kill #manpages
#avk47
ACCEPTED ANSWER
Score 45
kill
just sends a signal to the given process. The -9
tells it which signal to send.
Different numbers correspond to different common signals. SIGINT
, for example, is 2, so to send a process the SIGINT
signal issue the command
$ kill -2 <pid>
The manpage here specifies:
The default signal for kill is TERM.
The manpage also provides a table of signals you can send. According to this table, TERM
is 15
, so these are all equivalent:
kill <pid>
kill -15 <pid>
kill -TERM <pid>
Notice 9 is the KILL
signal.
Name Number Action
-----------------------
ALRM 14 exit
HUP 1 exit
INT 2 exit
KILL 9 exit this signal may not be blocked
PIPE 13 exit
POLL exit
PROF exit
TERM 15 exit [Default]
USR1 exit
USR2 exit
VTALRM exit
STKFLT exit may not be implemented
PWR ignore may exit on some systems
WINCH ignore
CHLD ignore
URG ignore
TSTP stop may interact with the shell
TTIN stop may interact with the shell
TTOU stop may interact with the shell
STOP stop this signal may not be blocked
CONT restart continue if stopped, otherwise ignore
ABRT 6 core
FPE 8 core
ILL 4 core
QUIT 3 core
SEGV 11 core
TRAP 5 core
SYS core may not be implemented
EMT core may not be implemented
BUS core core dump may fail
XCPU core core dump may fail
XFSZ core core dump may fail
ANSWER 2
Score 7
The default signal is TERM which allows the program being killed to catch it and do some cleanup before exiting. A program can ignore it, too, if it's written that way.
Specifying -9 or KILL as the signal does not allow the program to catch it, do any cleanup or ignore it. It should only be used as a last resort.
To see the list of numbers and signal names in Bash, use kill -l
(letter ell).
ANSWER 3
Score 4
I am using Ubuntu Linux.
Kill commands basically sends signal to process to end it. To simplify complex behavioral expectations of everyday computing kill command has various options along with it.
As explained above with all the kill numbers options corresponding to its definition.
I would like to add few lines to it.
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
As you see above these are all kill options you will get if you run Ubuntu Linux.
But certain kill signals are common across all *NIX flavors.
kill -9 is SIGKILL option and kernel can not ignore this signal, meaning it has honor this -9 or SIGKILL option and exit process immediately. Remember this process cannot be handled by application programs.
kill -15 on the other hand will send SIGTERM signal, meaning it will wait for process to cleanly shutdown before exit. This is default signal.