[Novalug] process kill 101

Nino Pereira pereira@speakeasy.net
Mon Apr 27 08:27:32 EDT 2009


Jon,

thanks a lot for the insight. I'll start using 'kill -9 nnnnn'
with restraint from now on

(snip) blow the sucker away with "-9".

>> My question is: what is the 'clean' way to make a process
>> disappear? I'm asking it because before I figured out the '-9'
>> option, a long time ago, processes seemed to hang around.
>> With '-9' they seem to disappear, but, if this isn't clean,
>> what is?
> 
> First surprise, the kill command doesn't kill anything.
> It sends a signal to a process.  That signal has a numeric
> value associated with it that conveys certain information
> to the process that receives the signal.  Try to run
> /bin/kill --table (has to be the one in a bin directory,
> not just kill --table).  This will print a list of the
> valid signals and their names/numbers.
> 
> For example, signal 14 means "you set an alarm clock,
> the alarm has rung".  If you run the sleep cmd, say
> sleep 20, the sleep process sets an alarm for 20 sec
> and receives signal 14 when it runs down to zero.
> 
> Signals are sent by lots of things.  Try doing some
> math and by mistake do 9 / (5 - 3 -  2) [i.e. divide
> by zero] and the math co-processor sends signal 8.
> Type a control-C, and the tty subsystem for your
> keyboard will send a signal 2 (your user requests
> that you interupt what you are doing).
> 
> The kill command, without a signal number argument,
> defaults to sending signal 15, software termination
> (some program has asked that you kill yourself).
> 
> Note, it is "kill yourself" not "be killed"; "interupt
> what you are doing", not "be interupted".
> 
> For most signals, a process that receives a signal
> can take one of three actions, ignore it, catch it
> and executes some signal handler code, or do the
> default action which is most often, branch the
> exit system call.
> 
> In the C language, kill(2/3) doesn't kill, it sends a
> signal.  Signal(2/3) doesn't send a signal, it sets up
> how the process will handle a signal when it receives one.
> I.e. will it ignore the interupt, commit suicide, or
> catch it and ask "do you really want me to die?".
> 
> A well written program will anticipate signals and
> ignore them during critical sections of code.  It will
> catch them other times and provide code to write out
> unwritten data, close open files and databases, remove
> temporary files, make log entries, etc.  Then it might
> kill itself.
> 
> Signal 9 (kill yourself; no questions asked) is a special
> case.  The possible actions are limited to one.  It
> can't be ignored, nor can it be caught and additional
> code executed.  It can only branch to exit(2/3).
> 
> So, if you kill one of those well written programs with
> signal 9, you circumvent the programmers good intentions
> and efforts.  That is why it should be the last resort.

Nino



More information about the Novalug mailing list