For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > how do I avoiding zombie processes without interfering with " die if system(ls)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how do I avoiding zombie processes without interfering with " die if system(ls)
Rahul

2006-01-10, 4:02 am

Hi

I have a script main.pl as follows



for ($i = 1; $i<=5000; $i++)
{
&foo();
}




sub foo {

if (fork() == 0){
# inside CHILD
# do something
exit 0;
else {
# inside PARENT
# do nothing
}
}

now, since the parent does not wait upon the child to finish (i don't want
it to explicitly wait, since i want to have multiple children run
simultaneously), so there are lot of zombie children left, thereby making
the system slow, and finally hang.

i researched a lot, there are 2 ways to avoid this.

1) $SIG{'CHLD'} = 'IGNORE';
2) $SIG{'CHLD'} = sub { while(waitpid(-1,WNOHANG)>0) {} } ;

also I have lots of calls such as
die if system("ls")
die if system("rm ..")
etc in my main parent routine as well as the child part of the foo()
routine...

So if I follow method 1) above to avoid zombie, the system() calls rreturn
error (as the inherent 'wait' has no child process to wait upon , as SIGCHLD
is ignored) (The ERRORS are seen only on perl 5.8.6 and not on perl 5.6.1)

If I follow method 2) above to avoid zombies, by writing my own handler, the
system() calls wait indefinitely as the child's SIGCHLD has already been
taken care of by my handler.


Could some1 help me avoid zombies without interfering with my system() calls
?

thanks,
Rahul

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com