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()?
while (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);
}
}
I'm running
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.