If I want to kill a process as careful and politely as possible,
which signals should I use in a kill command, in which order?

I would like to give the programm any kind of time to clean up, if it likes to, so just sending a SIGTERM will be to harsh, I think?

I'll use SIGKILL ("-9") last, that's clear.

But which to start? SIGHUP? Which signals are just a waste of time?

The relevant signals for reference, from

man 7 signal

  Signal     Value     Action   Comment
   SIGHUP        1       Term    Hangup detected on controlling terminal
                                 or death of controlling process
   SIGINT        2       Term    Interrupt from keyboard
   SIGQUIT       3       Core    Quit from keyboard
   SIGKILL       9       Term    Kill signal
   SIGPIPE      13       Term    Broken pipe: write to pipe with no
   SIGTERM      15       Term    Termination signal

SIGTERM is the way to go in my opinion. It has works in most of the cases. The ones in which this will not work, you'll have to do a SIGKILL anyway. SIGTERM gives process enough opportunity to release all the resources it has to and shut down cleanly.

|improve this answer|||||
  • 1
    @VolkerSiegel Aditya is correct, SIGTERM is the standard – Patrick Jul 29 '14 at 15:20
  • 2
    Many programs are safe to be sent SIGTERM. – 41754 Jul 29 '14 at 15:26
  • 1
    @VolkerSiegel You're thinking of SIGKILL. – Patrick Jul 29 '14 at 15:36
  • 5
    @VolkerSiegel You've got 3 different people telling you to use SIGTERM. If you're such an expert on signals, why did you even ask the question? – Patrick Jul 29 '14 at 15:43
  • 2
    @VolkerSiegel if a program isn't coded to catch SIGTERM and handle it "friendly" then chances are it isn't going to handle SIGINT friendly either. If a program is capable of a "friendly" termination from a signal, SIGTERM is almost assuredly going to be handled. Think of it this way: If you were writing a program that you wanted clean, friendly shutdowns, would you catch SIGINT but ignore SIGTERM? That makes no sense. – casey Jul 29 '14 at 15:50

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