Subject: | Lack of explicit wait fills up process table after thousands of forks |
OS: FreeBSD 6.3
Perl: 5.8.5
I wrote a script using Parallel::Fork::BossWorker 0.0.3 which forked
many processes. Even though worker_count was limited to 8 and there was
never more than 8 processes running at one time, after a thousand or so
forks the program would crash, usually with a fork failed error.
I believe the lack of an explicit wait() for the child filled up the
process table.
After I modified BossWorker.pm with the following diff, the failure
disappeared and fork never failed again.
*** ./site_perl/5.8/Parallel/Fork/BossWorker.pm Tue May 15 05:24:23 2007
--- /home/joechung/nfshome/Parallel/Fork/BossWorker.pm Mon Oct 13
22:13:25 2008
***************
*** 80,85 ****
--- 80,89 ----
close($fh);
}
}
+ # Wait for children lest proc table fills up
+ while ((my $pid = wait()) != -1) {
+ }
+
};
if ($@) {
***************
*** 101,107 ****
# Fork off a worker
my $pid = fork();
!
if ($pid > 0) {
# Boss
--- 105,112 ----
# Fork off a worker
my $pid = fork();
! (defined $pid) || confess("Fork failed: $!");
!
if ($pid > 0) {
# Boss