News for hackers. Stuff that matters.
Re:Learn Enough Command Line to Be Dangerous (Draft) by mhartl on Saturday September 19, 2015 @08:14PM (#10246038)
Could you expand on this? In my experience, kill frequently fails without -9, so I basically always include it (and it's never bitten me). I'm open to suggestions, though, so if you have a recommendation for a better way I'd appreciate the feedback. (Feel free to shoot me an email at the address in my profile.)
Re:Learn Enough Command Line to Be Dangerous (Draft) by atbattag on Saturday September 19, 2015 @09:06PM (#10246159)
As already stated, a process cannot respond to KILL signal, not allowing it to cleanup after itself. In many cases this may be OK or irrelevant, but you should never use -9 as a first resort. -9 is a last resort.

Ever kill -9 an unresponsive rails server process only to find that you have to manually rm the tmp server.pid file? That's because you used -9 ;).

Re:Learn Enough Command Line to Be Dangerous (Draft) by mhartl on Saturday September 19, 2015 @10:14PM (#10246327)
So would it be reasonable to recommend kill $pid as a first step and kill -9 $pid if that doesn't work? Bear in mind that this is a tutorial for beginners, so things like kill -15 $pid || kill -2 $pid || kill -1 $pid || kill -9 $pid (as another commenter suggested) aren't appropriate, but I feel like kill is too important a command to leave out completely.
Re:Learn Enough Command Line to Be Dangerous (Draft) by atbattag on Saturday September 19, 2015 @10:44PM (#10246389)
Suggesting kill first before kill -9 seems like a good idea. Like you said kill is an important tool. Like you said this is for beginners so its up to you how much more detail to go into with the command.
Re:Learn Enough Command Line to Be Dangerous (Draft) by mhartl on Saturday September 19, 2015 @11:43PM (#10246496)
Great, thanks for the suggestions.
Re:Learn Enough Command Line to Be Dangerous (Draft) by userbinator on Sunday September 20, 2015 @01:24AM (#10246646)
On the other hand, it seems almost all the times when I've had to use kill it's because the process has already refused to die by more normal means and I doubt it'd respond to a non-9 kill.
Re:Learn Enough Command Line to Be Dangerous (Draft) by mmagin on Saturday September 19, 2015 @08:34PM (#10246093)
kill -9 is like rm -rf. Sometimes you need it, but it's the path of maximum destruction. In the case of kill, signal 9 (SIGKILL) is a signal that processes cannot trap, so they immediately end without any chance of cleanup or saving state. Unless you really don't care about data the process may have been working with, it's usually best to try a plain kill (sending SIGTERM) first.
Re:Learn Enough Command Line to Be Dangerous (Draft) by lloydde on Saturday September 19, 2015 @08:37PM (#10246097)
Fails? Frequently? In whet contexts? Was the process already suspended?

The process might have been processing the SIGTERM and shutting down cleanly, but we are impatient so we -9, SIGKILL it, knowing that it can't process that signal and will be terminated (as long as its parent is alive). Or you are correct and there are many scenarios where it will be ignored.

Oh, the developer is walking by and I mention the "hang" to him. He replies, "did you kill -3, SIGQUIT, to generate a core? No? Bye."

Need the process to re-initialize, does the program have a SIGHUP handler?

kill is more geneneral than the name implies, though I agree signaling is an intermediate topic.

Re:Learn Enough Command Line to Be Dangerous (Draft) by dkharrat on Saturday September 19, 2015 @11:34PM (#10246487)
An example where kill -9 can screw things up is killing a database process (e.g. MySQL, mongo, etc). Killing it with -9 will most likely lead to data corruption/loss, as the process might be in the middle of flushing to disk for example.
Re:Learn Enough Command Line to Be Dangerous (Draft) by ryanpetrich on Sunday September 20, 2015 @01:37AM (#10246672)
Any database that can't recover from kill -9 is not worth trusting your data with.