7

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
                                 readers
   SIGTERM      15       Term    Termination signal
3

1 Answer 1

14

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.

19
  • 1
    @VolkerSiegel Aditya is correct, SIGTERM is the standard Commented Jul 29, 2014 at 15:20
  • 2
    Many programs are safe to be sent SIGTERM. Commented Jul 29, 2014 at 15:26
  • 1
    @VolkerSiegel You're thinking of SIGKILL. Commented Jul 29, 2014 at 15:36
  • 6
    @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? Commented Jul 29, 2014 at 15:43
  • 3
    @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. Commented Jul 29, 2014 at 15:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.