The advice to never ever use `kill -9` is too strong. It's fine to use if you know what the program you are killing does.
In my case, processes I have to `kill -9` are
- programs that only read data files (or write to dispensable files)
- programs that I know don't react to SIGTERM (there is no cleanup logic, but still something makes them swallow SIGTERM)
- often then are simple tools (e.g. ls) that become wedged in a system call or in kernel code (when trying to access a bad NFS share)
- in the other cases they are in-house programs that are either badly written, or too complex (the worst offender is CERN's ROOT, if it becomes wedged you have to `kill` and `kill -9` several processes it spawns), or where we don't care enough to fix them
Interestingly, there seem to be some cases where even `kill -9` doesn't help. What I do then is to freeze the process with Ctrl+Z (Ctrl+C doesnt work of course), and then `killall -9 $(jobs -p); fg`.
Actually, I have one program I routinely call with `program; killall -9 $(jobs -p); fg` and end it with Ctrl+Z. Sad, but true.
(Of course, if your process is a database or a GUI tool or something, then all the standard wisdom against `kill -9` applies.)
In my case, processes I have to `kill -9` are
- programs that only read data files (or write to dispensable files)
- programs that I know don't react to SIGTERM (there is no cleanup logic, but still something makes them swallow SIGTERM)
- often then are simple tools (e.g. ls) that become wedged in a system call or in kernel code (when trying to access a bad NFS share)
- in the other cases they are in-house programs that are either badly written, or too complex (the worst offender is CERN's ROOT, if it becomes wedged you have to `kill` and `kill -9` several processes it spawns), or where we don't care enough to fix them
Interestingly, there seem to be some cases where even `kill -9` doesn't help. What I do then is to freeze the process with Ctrl+Z (Ctrl+C doesnt work of course), and then `killall -9 $(jobs -p); fg`.
Actually, I have one program I routinely call with `program; killall -9 $(jobs -p); fg` and end it with Ctrl+Z. Sad, but true.
(Of course, if your process is a database or a GUI tool or something, then all the standard wisdom against `kill -9` applies.)