Wednesday, October 24, 2012

Common Linux Termination Signals

People issuing a kill -9 on production servers blindly should read this:

If you have ever used Linux terminal, I think you should know what Linux Termination Signals are. They are the signals that you usually supply with kill command when you are trying to kill a process. Depending upon the provided signal further actions can be taken.

  • SIGTERM: It is the default signal used by kill command. This signal can be handled by the process in the sense that process can choose to ignore this or do some specific action upon receiving this signal. It is like politely asking someone to do something.
  • SIGKILL: This is the signal sent when you supply -9 as argument to the kill command. This signal cannot be handled or ignored. Process has to die as a result of this signal. Usually this is the last resort thing. If there is a process which is not dying even after receiving a SIGKILL then you should report it to upstream. It is most likely some sort of bug in distribution or the app itself.
  • SIGHUP: This signal tells the process that user's terminal is disconnected somehow. Usually this happens when you ssh pipe gets broken or you face network connectivity issues etc.
You can get a list of available signals for your distribution by firing kill -l on terminal. For my Fedora 17 box there are 64 signals available. I think the number would be the same for the distributions following POSIX standard.

UPDATE: (As mentioned by @MarcusMoeller on twitter) SIGHUP is commonly used by daemons to reload config files.

2 comments:

  1. Good post.

    My rule of thumb is:

    SIGHUP - Please respawn.
    SIGTERM - Please quit.
    SIGKILL - DIE! DIE! DIE!

    I think I prefer kill -KILL better than kill -9 because I get to type "kill" twice, and once in all caps. ;-)

    ReplyDelete
    Replies
    1. Yeah, and I think kill -HUP and kill -TERM will pass hup and term respectively. Never tried them though.

      Delete

Note: Only a member of this blog may post a comment.