16

Posting this question because I was surprised to not find it directly answered; apologies if this is a duplicate - I did look!

I have heard that kill -9 or kill -SIGKILL is bad, but I don't understand why. If I shouldn't kill -9 what should I do to kill a process?

2
  • 2
    The premise of the question is wrong. SIGKILL is just a tool. It is recommended in some situations and not recommended in other situations (as are all other tools).
    – kubanczyk
    May 6, 2016 at 10:33
  • @kubanczyk sure, but it's an oft-misapplied tool, and used without understanding it's purpose. I've seen many threads where A says "Just kill -9 it", OP says "great, that worked! I'll remember that from now on!", and B comes in to warn "wait kill -9 is dangerous!" only after the fact.
    – dimo414
    Jun 12, 2017 at 17:44

1 Answer 1

20

SIGKILL pulls the rug out from your running process, terminating it immediately. For very simple programs this is fine; in practice however there are very few "simple" programs.

Under the covers even trivial-seeming programs do all sorts of transactional work that they need to clean up from before terminating (think of the finally block in Java and other programming languages), such as closing resource handles, deleting temporary files, and flushing data from memory to disk. You cannot anticipate when a program might be doing something like this.

If you're lucky you won't notice anything amiss if you send a SIGKILL, but you can't be lucky forever, and you may not know anything's gone wrong until it's too late to recover what's been lost.

You should almost never need to send a SIGKILL, and you should be sure you've exhausted your alternatives before doing so. In many cases rebooting (which will eventually send SIGKILLs to misbehaving programs) is safer than manually sending a SIGKILL yourself. I can probably count on one hand the number of times I've needed to send a SIGKILL (and likely all of my own making).

Generally speaking you can use Ctrl+C (which sends the foreground process a SIGINT) or SIGTERM (as in "terminate") to instruct a process to stop what it's doing and exit.

Some further reading:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .