Image of the glider from the Game of Life by John Conway
Skip to content

Appropriate Use Of "kill -9 "

There are times when "kill -9" is the only time you can kill a PID that is behaving badly. However, it's usually not needed if you know your signals. When I encounter a badly behaving program, here is the procedure I usually take.

First, I'll send a SIGTERM (kill -15) to the PID. Sometimes this works, sometimes this doesn't. However, SIGTERM is a clean shutdown of the program. It will flush any data to disk that needs to be written, clean up the memory registers, and close the PID.

If that doesn't work, then I will send a SIGHUP (kill -1). This will generally cause the program to restart. Restarting the program will flush any data to disk that needs to be written, and cleans up the memory registers, then restarts the program.

If that doesn't work, then I will send a SIGINT (kill -2). This is an interrupt from the keyboard signal. This is equivalent to sending a CTRL-C to the PID. This is useful when the PID is not in the terminal foreground, but has been backgrounded as a daemon process.

If that doesn't work, then I will send a SIGSEGV (kill -11). This causes the program to experience a segmentation fault, and close the PID. It won't flush any data that needs to be written to disk, but it may create a core dump file that could be useful in debugging, on learning why the program was behaving the way it was. The logging facility for that core dump is through the kernel.

At this point, if none of the above signals have worked, only then will I issue a SIGKILL (kill -9). However, using this signal is potentially dangerous, as it is equivalent to ripping its feet out from under it. It will not sync any data, at all, to disk. No unwritten data, no debugging data, no logging data, no nothing. It's equivalent to using a sledge hammer to sink a nail.

Further, at this point, if I haven't been able to clean up the PID with the previous commands, then a SIGKILL usually won't clean up the PID either. Using SIGTERM, SIGHUP, SIGINT and SIGSEGV usually clean up 80% of the PIDs I wish to clean. When I need to issue SIGKILL, I'm met with maybe 50% success.

{ 11 } Comments

  1. Samundra Shrestha | August 14, 2012 at 12:26 pm | Permalink

    Wow !!! This is really very helpful information. I always used to use kill -9 but now onwards will be using your suggestions 🙂 Thanks for the info.

  2. Carroarmato0 | August 14, 2012 at 12:43 pm | Permalink

    Wow thanks for the blog post. I've been using Linux for quite some years now and also had to deal with misbehaving processes once in a while. I usually try to send a SIGTERM to the processes before trying a SIGKILL. But I didn't know or use the other possible signals not knowing their effect. Thank you for clearing that up.

  3. Jason | August 14, 2012 at 3:35 pm | Permalink

    Frankly (and I don't blame you) I think for the average joe thats way too much effort, now if there was a program perhaps esckill (esculating kill) that did all that for me on supply of a PID I'd happily do it, but other than that I'll stikc -9 as it works for me, and I've yet to encounter any problems with corruption afterwards.

  4. Jonathan Carter | August 14, 2012 at 7:26 pm | Permalink


  5. Banpei | August 14, 2012 at 10:35 pm | Permalink

    Why SIGSEGV instead of SIGQUIT? Its default action is to dump core and it's bound to Ctrl-\

  6. Thor Dekov Buur | August 15, 2012 at 12:49 am | Permalink

    Great post, thank you! I've used kill -9 for ages and never thought it might be a problem.

  7. lo0m | August 15, 2012 at 1:29 pm | Permalink

    Thanx, this article cleared it a lot for me !

  8. desgua | February 21, 2013 at 6:36 am | Permalink

    I have made a script to automate what you taught us.

    Here it is at pastebin:

    Thank you!

  9. chandrika | January 29, 2014 at 7:25 am | Permalink

    Thanks for this post. I have had ADT hang twice and had to reinstall it to access my projects again after doing a quit process in Activity Monitor.
    This time I used a Kill -15 pid in the terminal window and could easily restart it.. Thanks again.

  10. Rhyven | March 22, 2015 at 3:16 pm | Permalink

    Thanks for sharing, Desgua!

  11. dubailife | December 1, 2017 at 8:29 am | Permalink

    VIP UAE Girls Find VIP Dubai escorts online today at bunnies listing. Enjoy the elite hot girls company

Post a Comment

Your email is never published nor shared.