How do I check whether a process has died by using process ID in C?

How do I check whether a process has died by using process ID in C?

Post by xie.. » Fri, 23 Jan 1998 04:00:00



Can anyone tell me how to detect the status of a process. Basically, I
just want to know whether it's dead or alive.
Show me the functions in C.

Thanks.
Min

 
 
 

How do I check whether a process has died by using process ID in C?

Post by t.. » Fri, 23 Jan 1998 04:00:00


: Can anyone tell me how to detect the status of a process. Basically, I
: just want to know whether it's dead or alive.
: Show me the functions in C.

What is your definition of dead or alive ?

Maybe kill(2) will be sufficient for your needs ?

Make sure that you appreciate and can differentiate between 'alive and
processing' and 'supposedly alive but in fact zombie/defunct/not processing'.

IAP

 
 
 

How do I check whether a process has died by using process ID in C?

Post by Mikko Tyolajar » Fri, 23 Jan 1998 04:00:00



>Can anyone tell me how to detect the status of a process. Basically, I
>just want to know whether it's dead or alive.
>Show me the functions in C.

To just see if a certaing pid is still around or not, try something like:

#include <errno.h>
#define ISALIVE(PID) ( !( kill((PID), 0) < 0 && errno == ESRCH ) )

On Solaris 2.x (or at least 2.5 and 2.6) you can use poll(2) on a file under
/proc to detect the demise of a process.  See proc(4).

        /Mikko
--

 DynaSoft

 
 
 

How do I check whether a process has died by using process ID in C?

Post by Vic Abe » Fri, 23 Jan 1998 04:00:00



>Can anyone tell me how to detect the status of a process. Basically, I
>just want to know whether it's dead or alive.
>Show me the functions in C.

        man -s 2 kill