On Thu, Feb 08, 2001, Oded Arbel wrote about "Finding if a process is runing.":
> I'vre read somewhere (I think in one of perl's man pages) that you can use
> kill to send a "0 signal" to a process, to see if it is still runing. the
> kill(2) man page seems to confirm that, saying that if sig is 0, no signal
> will be sent, but error checking is till performed - from which I came to
> the conclusion that it will check that there is a process with the pid I
> have and return an error code otherwise (btw - did you know that KDE2 has
> a 'man pages' kio_slave ? try 'man:kill' in your konqi's location bar :-)
> anyway, to my problem : I tried to use that method to check if a sub
> process I forked is still runing, and instead of returning 0 correctly (I
> checked with ps, the sub process is indeed running), it returns with the
> error code "Invalid argument". how come ?
This is indeed true on modern Unix versions. Sending a signal number "0"
to a process only checks whether it exists _and_ you are allowed to kill
it. You can check it with your shell's normal "kill" command. For example:
$ kill -0 28492
$ kill -0 28352
kill: kill 28352 failed: operation not permitted
$ kill -0 28490
kill: kill 28490 failed: no such process
Where 28492 is my process that exists, 28352 is root's process (I'm not
allowed to kill() it, even with a "fake" signal), and 28490 is a non-existant
process.
check the kill(2) manual for the error codes returned by the kill() system
call. "Invalid argument" (EINVAL) means that you specified an invalid signal.
0 is _not_ an invalid signal, so maybe you got the code wrong - can you
post a short code section?
The diagnostics you should expect from kill() is either success, or failure
with errno being ESRCH (the process does not exist), or EPERM (the process
does in fact exist, but it is not yours).
Watch out - I'm not sure what kill(2) does with zombie processes (processes
that died but have not been wait(2)ed on) - kill() might report these processes
exist.
--
Nadav Har'El | Thursday, Feb 8 2001, 15 Shevat 5761
[EMAIL PROTECTED] |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Can Microsoft make a product that
http://nadav.harel.org.il |doesn't suck? Yes, a vacuum cleaner!
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]