Shaun Abram
Technology and Leadership Blog
Don’t use “kill -9”
In the past, any time I wanted to stop an errant process on unix, I just used “kill -9”. By default. Without thinking about it much.
Then a colleague commented to me that you should never use kill -9. It terminates the process with no chance to shutdown in an orderly manner, and so can leave things in a bad state, such as corrupting files. “But what else am I supposed to do!?” I naively asked.
There are of course many other options for the kill command (see links below), but here are some alternatives you can try, in the order you may want to try them.
Number | Name (full) | Name (short) | Description | Notes |
---|---|---|---|---|
15 | SIGTERM | TERM | Terminate | This is the default. Give the process a chance to finish what it's doing and clean up. Some programs may not respond however. |
2 | SIGINT | INT | Interrupt | Similar to pressing CTRL+C during execution. Most programs will stop. |
9 | SIGKILL | KILL | Kill | Forced termination. Just kill it. |
Actually for 1 (HUP), 2(INT) and 3 (QUIT) the differences seem subtle are are discussed here, but 2(INT) seems as good as any as the interm between the polite request of 15 (TERM) and the forced stop of 9 (KILL).
Note that you can use the full name, short name or number with the kill command. All these do the same:
- kill -15 1414
- kill -SIGTERM 1414
- kill -TERM 1414
Links:
Tags: bash, commandline, kill, unix