How can a parent find out if one of its children is still alive

john.lupien jrl at cbnews.att.com
Wed Jun 6 06:13:51 AEST 1990


In article <6334 at ozdaltx.UUCP> toma at ozdaltx.UUCP (Tom Armistead) writes:
>In article <30408 at cup.portal.com>, DeadHead at cup.portal.com (Bruce M Ong) writes:
>> I am sure there is a very easy way to do this, but I just havent
>> figured this one out:
>> 	How can a parent find out if one of its children is still alive
>> or not without
>If you have the process id of the child you can use kill(2) to find out if
>it is still there.
>i.e.:   if( kill( child_pid, 0 ) == -1 )
>            puts( "The child is dead" );
>Signal 0 is called the NULL signal and is used to validate a process id, no 
>signal is actually sent to the destination process.

This is nice in that, with a small 
change, you can use it to find
out if processes belonging to
other uid's are alive, provided
you know their pid. If kill(child_pid, 0)
returns other than -1, the process exists
and you have permission to kill (007?)
If it returns -1 and an errno of ESRCH,
the pid does not exist, otherwise you
typically get errno of EPERM.


-- 
	-John Lupien
	mvuxr!jrl
	jrl at mvuxr.att.com



More information about the Comp.unix.wizards mailing list