My man page does not document the difference between

kill <pid>

and

kill -9 <pid>

Since these do different things why is the -9 not documented in the kill manpage? I thought maybe it was a shell specific things so I looked in the bash man page too but no luck.

Bonus question: what does the -9 do?

link|improve this question

feedback

2 Answers

up vote 14 down vote accepted

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
link|improve this answer
4  
The default signal(kill <pid>) is TERM. – heavyd Feb 11 '10 at 13:59
4  
The numbers are usually, but not always, the same on different Unix-based systems. It's better practice to use the signal name. That is, instead of kill -9, use kill -KILL. – mpez0 Feb 11 '10 at 14:42
3  
I would add that the KILL and STOP signals are so-called non-catchable signals. That means when a TERM signal is sent to a process, it is able to catch it and perform various "shutdown" operations it needs to do. The KILL signal stops the process immediately. – Neo Feb 11 '10 at 14:53
2  
It's best to use the default signal first and only use -9 if the default doesn't work. The reason for this is that -9 can't be caught so the program doesn't have a chance to do any cleanup. Also, you find the documentation for signals on your system in man 7 signal – Dennis Williamson Feb 11 '10 at 17:17
feedback

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).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.