Jonathan has asked for the wisdom of the Perl Monks concerning the following question:
I have a process that polls for files and forks a child process to handle each file as it arrives.
The problem is that sometimes it waits for the child to exit before moving on to the next This seems to happen when processing the larger files.
Below is the bare bones of the processing with the error checking removed.
What am i doing wrong? Would it be better to do a double fork()?
The problem is that sometimes it waits for the child to exit before moving on to the next This seems to happen when processing the larger files.
Below is the bare bones of the processing with the error checking removed.
What am i doing wrong? Would it be better to do a double fork()?
I'm runningwhile (1) { # Loop other processing here. load_file($this_file); reap_children(); } sub load_file() { my $childProcess; $childProcess = fork(); unless($childProcess) { # Child process so lets exec the loader. exec("loader $this_file"); exit 0; } } sub reap_children() { my $kid = 1; while ($kid > 0) { $kid = waitpid(-1, 1); } }
perl -V Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=solaris, osvers=2.6, archname=sun4-solaris uname='sunos lonxpr1732 5.6 generic_105181-10 sun4m sparc sunw,spa +rcstation-5 ' hint=recommended, useposix=true, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef
Back to
Seekers of Perl Wisdom