Perl child processes become zombie on a multi-core processor
Hi,
I am learning about forking and IPC in perl.I have written a simple script which has to find required patterns from a bunch of files ( where each file is around 2 GB each,which contain the output of seq 1 10000000000000) on an 8 core machine. I am current forking 6 child processes which run simultaneously on 6 cores of the processor & have to search for the required pattern in 6 different files & inform the parent process when a pattern is found using a PIPE. The problem is,when a child process is done reading a text file looking for a pattern,it is becoming a zombie process.It exits cleanly when i put a $SIG{CHLD} = "IGNORE"; in the script. Can any one tell me whats going on & how do i improve the communication between child and parent processes?Sorry for such a long question.Thanks. Code:
|
|
Hi wje,
Quote:
I'll do what ever you said in your post,thanks a lot for the input. But my Q was ,why child processes turned into a zombie process,once they are done? Is that because they were not able to update their exit status to the parent,as parent is stuck in a while loop ? |
Quote:
What that does is test, once, now, whether the process is complete. Since the processes last about an hour each, that call basically has no effect, because you're testing just when the processes have started. What that call would do, if the process were actually done, is to harvest the completion status of the process. For example, if it died due to a signal (example: SIGTERM), what was the signal? If it exited normally, what was the exit code? And so on. Until you actually do that, you're going to have a zombie process. Zombie processes don't do anything; they just stick around until you can do the wait() or waitpid(). When the parent process gets end of file on a particular pipe, that would be a good time to do a waitpid(process number,0). Otherwise, you'll have zombie processes hanging around until the parent exits. When the parent exits, any unharvested zombie children get passed to the parent's parent, which in most cases means process 1 gets them almost immediately and waitpid()s them out of existence. |
All times are GMT -5. The time now is 05:40 PM. |