rasputin.dnsalias.com

Posted on February 7, 2007 7:41 AM by chadley

I was reading a useful article called Web Developers: 13 Command Line Tricks You Might Not Know

Most of the stuff there is pretty good, although in true Computer Geek form, I already knew that.

I did take exception to one section of that post however:

Quote:

The -9 basically kills the process with extreme prejudice, it will die immediately.


Boy, as a sysadmin type I hate it when I see people say this. They make it sound like kill -9 is just a more powerful kill, like a higher caliber bullet or something. kill -9 should not be the default kill command you use. You should try using kill without -9 first, since when you use the -9 option, it will leave behind child processes that then run until they die or the next reboot. kill -9 means die now and don't clean up anything.

If you issue the kill command and the process doesn't die right away, it may be trying to clean up, especially if you're killing a command-line database script.

That being said, kill -9 CAN be used when you kicked off a process 2 hours ago that runs for 6 hours, and you want to go home for the day. Just ctrl-z the proc and then bg it, then you can kill -9 the shell that called it, which should leave your background process running. This can be useful for doing a fire and forget ftp download, if you don't have access to screen or vnc or something.

This post has been looked at 277 time(s).

Tags: , , ,

Posted on February 7, 2007 9:31 AM by kailden

In fact, assuming you want to kill process #987324 the best way to go is:


kill 987324

(count to 10 mississippi)

kill -INT 987324

(10 more seconds)

kill -HUP 987324

(hello....10 more seconds)

kill -KILL (or -9) 987324

which will send the terminate, interrupt, hangup and finally kill signals to the process in an attempt to wake it up from its hung state, and allow it to clean up. That's where nohup gets its name: it ignores the HUP signal, but not the INT. I see lots of folks kill nohup's processes with KILL when a simple TERM or INT would do.


Sometimes sysadmins write that into a script, and change the name of kill to reallykill, so that the average user kills things correctly.

See Useless use of kill -9 for more info.
You are NOT logged in. You MUST login to add a comment at this time.
Username:
Password:
Comment Title:
Comment: