I understand it's off topic, I couldn't find anywhere online and I was thinking maybe programming gurus in the community might know this.
I usually use
kill -9 pid
to kill the job. I always wondered the origin of 9. I looked it up online, and it says
"9 Means KILL signal that is not catchable or ignorable. In other words it would signal process (some running application) to quit immediately" (source: http://wiki.answers.com/Q/What_does_kill_-9_do_in_unix_in_its_entirety)
But, why 9? and what about the other numbers? is there any historical significance or because of the architecture of Unix?
I don't think there is any significance to number 9. In addition, despite common believe,
kill
is used not only to kill processes but also send a signal to a process. If you are really curious you can read here and here.There’s a very long list of Unix signals, which you can view on Wikipedia. Somewhat confusingly, you can actually use
kill
to send any signal to a process. For instance,kill -SIGSTOP 12345
forces process 12345 to pause its execution, whilekill -SIGCONT 12345
tells it to resume. A slightly less cryptic version ofkill -9
iskill -SIGKILL
.there are some process which cannot be kill like this "kill %1" . if we have to terminate that process so special command is used to kill that process which is kill -9. eg open vim and stop if by using ctrl+z then see jobs and after apply kill process than this process will not terminated so here we use kill -9 command for terminating.
The
-9
is the signal_number, and specifies that the kill message sent should be of the KILL (non-catchable, non-ignorable) type.Which is same as below.
Without specifying a signal_number the default is -15, which is TERM (software termination signal). Typing
kill <pid>
is the same askill -15 <pid>
.First you need to know what are Signals in Unix-like systems (It'll take just few minutes).
There are several types of Signals we can use - to get a full list of all the available/possible Signals use "$ kill -l" command:
In the above output it's clearly visible, that each Signal has a 'signal number' (e.g. 1, 2, 3) and a 'signal name' (e.g. SIGUP, SIGINT, SIGQUIT) associated with it. For a detailed look up what each and every Signal does, visit this link.
Finally, coming to the question "Why number 9 in kill -9 command":
There are several methods of delivering signals to a program or script. One of commonly used method for sending signal is to use the kill command - the basic syntax is:
Where signal is either the number or name of the signal, followed by the process Id (pid) to which the signal will be sent.
For example - -SIGKILL (or -9), signal kills the process immediately.
and
both command are one the same thing i.e. above we have used the 'signal name', and later we have used 'signal number'.
Verdict: One has an open choice to whether use the 'signal name' or 'signal number' with the kill command.
Both are same as kill -sigkill processID, kill -9 processID. Its basically for forced termination of the process.