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?
Why should I not use 'kill -9' / SIGKILL
process;kill
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:Differences between kill signalsWhat does -9 mean?How to terminate a process for goodAppropriate order to send different kill signals