KILL! KILL! KILL! (of Unix processes)
08/01/2018 4 Comments
The start of this isn’t my post – I got it from here: but I wanted to reblog/repost and enhance it because as far as I can tell, 99% of all known DBA’s only use kill -9 to remove unhappy processes.
Original Post:
Useless Use of Kill -9 form letter
No no no. Don't use kill -9. It doesn't give the process a chance to cleanly: 1) shut down socket connections 2) clean up temp files 3) inform its children that it is going away 4) reset its terminal characteristics and so on and so on and so on. Generally, send 15, and wait a second or two, and if that doesn't work, send 2, and if that doesn't work, send 1. If that doesn't, REMOVE THE BINARY because the program is badly behaved!** Don't use kill -9. Don't bring out the combine harvester just to tidy up the flower pot.
**don’t remove your Oracle or any other binaries please.
I hope you found that useful. I know I did. But what do the numbers mean? Well, they are increasingly violent ways to ask the program to stop itself. The command kill -9 isn’t asking the program to stop, it’s asking the O/S to stop running the program now, regardless of what it’s doing.
Run order of kills:
kill -15 : this is the equivalent of kill -sigterm and it the default. The program should terminate after it has finished what it is doing.
kill -2 : this is the equivalent of kill -sigint and is the same as pressing CTRL+C. This should mean “stop what you’re doing” — and it may or may not kill the program.
kill -1 : this is the equivalent of kill -sighup and tells the program that the user has disconnected. (e.g. SSH session or terminal window was closed). It usually results in a graceful shutdown of the program.
The executing program needs to be coded to recognise these kill signals, and all good software will spot them.
The other fun kill command is kill -sigstop. This can’t be blocked (like -9) as it’s an O/S level command too, but freezes the program execution like pressing CTRL+Z. You can continue the program execution later using kill -sigcont.
This is all true, but kill -9 is so so mighty that sometimes it is impossible to restrain ourselves from using it ;).
Good post, thanks for sharing
LikeLiked by 2 people
Reminds me of this little trick I posted a few years ago. http://dbaharrison.blogspot.co.uk/2014/06/ever-forgot-to-nohup-your-command-this.html?m=1
LikeLiked by 1 person
Good example.
LikeLike
From @ @kevinclosson on twitter – reproduced as a comment as as it’s really worth knowing
“An age old trick to “goose” a catatonic user mode process is to SIGSTOP/SIGCONT. These signals cannot be ignored and *will* put the process into any existing signal handler. If that doesn’t work, murder the process because it’s sick”
LikeLiked by 1 person