PDA

View Full Version : Zombies and Multiprocessor???



3dkiwi
12-13-2006, 10:02 PM
I am having a problem with fork() and the child processes becoming zombies.

I am using the code from the Advanced Linux Programming book that sets up a simple
web server that forks child processes to handle requests. This is all working OK but
when the child processes complete they are not being cleared correctly by the
signal handler clean up function that calls the wait() function.

I am wondering if there is anything that needs to be done beyond the code from
the book if this program is running on a Dual Processor machine?

Cheers in advance
Jim

Kennedy
12-13-2006, 10:35 PM
I have always had to use waitpid() to get the zombies gone.

3dkiwi
12-13-2006, 11:07 PM
Kennedy

Just rechecked, and yes I am using wait() so will try waitpid() and get back to you.

Need to do some more readup on this call to make sure it does not break other things.

Thanks for the prompt reply.

Cheers
Jim

3dkiwi
12-14-2006, 04:48 PM
Kennedy

Tnx for that.

I changed the wait(&status) to waitpid((pid_t)-1, &status, 0) and seems to be working like a charm.

Once I have finished off some details I will publish what I was doing at:

http://www.pyenet.co.nz/legrob/index.html

Cheers
Jim

3dkiwi
01-05-2007, 05:07 PM
After letting the process run for a while longer it seems that the Zombie issue is not resolved correctly.

However I now have finished my webpage on the information for the Parallel Port Interface I constructed. Check out:

http://www.pyenet.co.nz/legrob/parallelportinterface.html

Cheers
3d

Kennedy
01-06-2007, 12:32 AM
Looks to me like you are missing some of the processes. . . pid_t would be a process number???? if so, then you are looking for the process number pid_t - 1, which wouldn't be the pid_t. . . If you want to clean up ANY zombie, you'd send -1 in stead of pid_t - 1, however, this would not tell you which process has ended. Here is a chunk from the man page:

The value of pid can be one of:

< -1 which means to wait for any child process whose process group ID is equal to the absolute value
of pid.

-1 which means to wait for any child process; this is the same behaviour which wait exhibits.

0 which means to wait for any child process whose process group ID is equal to that of the calling
process.

> 0 which means to wait for the child whose process ID is equal to the value of pid.


Hope this helps! (BTW, from what I can recall [and it has been 10+ years] the process waitpid(-1, NULL, WNOHANG) would clean up all children that have returned).