I am attempting to use "kill(pid, 0) == 0" to determine if a child process is running. It doesnt seem to be working as advertised. I have a parent C program that spawns a child C program on a unix box. Supposedly, the 'kill' statement listed above will return true if the 'pid' is still running, but wont return 0 if it isnt. In my case, I run the 'kill' command after I have manually killed the child process and it still says the child process (a.out) is running. Here is a snippet of the code that I ran:
parent.c
Code:
int main()
{
char *args[2];
int p1;
p1 = vfork();
if (p1 == 0)
{
args[0] = "./a.out";
args[1] = NULL;
execv("./a.out", args);
}
sleep(20);
if (kill(p1, 0) == 0)
{
printf ( "running");
}
else
{
printf ("not running");
}
child process
Code:
int main()
{
char *xxx;
sleep(2);
strcpy(xxx, "somethign"); /* to manually kill this program */
}
any ideas?