Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fork( ) in Perl Help!!

Status
Not open for further replies.

mackiew

Programmer
Sep 15, 2000
18
0
0
UY
I am having this problem:
I have Perl script that uses a “for” to launch many processes children using “fork”, the problem is that: the children are left zombies, and therefore arrives at a point in which we cannot create more processes .
We thank for any aid that can give us. Our code is:

for ($count = 0; $count <= 100; $count++) {
FORK: {
if ($pid = fork){
# father code ;
} elsif (defined $pid) {
# children code
}
exit ;
} elsif ($! =~ /Resource temporarily unavailable/){
print &quot;Couldn’t create process&quot;;
sleep 5;
redo FORK;
} else{
# failure
die &quot;can’t fork: $! \n&quot;;
}

}
}

[sig][/sig]
 
Mac,

You just have to wait() for your child processes. The fork() function returns the process id of the child just started and you can use that to wait() for it. [sig][/sig]
 
Hello Mike :

I would like to avoid using wait, because i dont want that the father waits for every child to finish, because i am launching *many* children, and i want them to run *all* concurrently

Thank you very much. [sig][/sig]
 
ok.....

In which case they will all leave zombie process table entries. But that's the only resource they take up so there really isn't a problem with just increasing the size of your process table to accomdate them. What O/S are you running on? [sig][/sig]
 
Which trick on that page did you use Mac? [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top