CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
too many zombies with fork

 



Omicron
Deleted

Nov 9, 2000, 6:46 AM

Post #1 of 4 (1279 views)
too many zombies with fork Can't Post

Hello,

I am having a problem with a PERL script.

Any help would be great fully received,
I have Perl script that uses a “for” to launch many processes children using “fork”.
The problem is the child processes in my script are spawning zombies. (I closed every Child process with exit)
The result of these zombies is that they fill up the process table allowing no new processes to be created.

I have tried the following code to fix to problem but to no avail.

$SIG(CHILD) = sub {wait}


DrZed
User

Nov 27, 2000, 1:38 PM

Post #2 of 4 (1280 views)
Re: too many zombies with fork [In reply to] Can't Post

Well.... either your not actually exiting each child, or the child processes are forking more processes before they exit.

If you can show your code, it would help.


perlplexer
Deleted

Nov 28, 2000, 5:49 AM

Post #3 of 4 (1279 views)
Re: too many zombies with fork [In reply to] Can't Post

Well, I guess you can refer to Perl Cookbook since someone put it online (hopefully they've got a licence for it ;) )
http://hrg.dhtp.kiae.ru/corvin/perlbs/cookbook/ch16_20.htm


Danni
Deleted

Mar 27, 2001, 12:54 PM

Post #4 of 4 (1252 views)
Re: too many zombies with fork [In reply to] Can't Post

Theres a few methods you can use to prevent zombie processes.

Basic Method
This method uses a blocking wait call to wait on the child processes. Kind of defeats the point, however.


if ($pid = fork()) {
# The Parent
waitpid ($pid,0);

} else {
# The Child
}





SIGCHLD Method
This method allows multiple processes at one time, much faster but ive found it to cause out of memory errors. Insert before the fork() call.

use POSIX ":sys_wait_h";
$SIG{CHLD} = /&waitchild;
sub waitchild {
while(waitpid(-1,&WNOHANG) > 0) {}
$SIG{CHLD} = /&waitchild;
}




Hope this helps.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives