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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: fork()ing a large process
by maverick (Curate) on Nov 29, 2001 at 22:04 UTC | |
by Jonathan (Curate) on Nov 29, 2001 at 22:23 UTC | |
Re: fork()ing a large process
by dws (Chancellor) on Nov 29, 2001 at 22:20 UTC | |
by tye (Sage) on Nov 29, 2001 at 22:34 UTC | |
by Jonathan (Curate) on Nov 29, 2001 at 22:47 UTC | |
Re: fork()ing a large process
by traveler (Parson) on Nov 29, 2001 at 22:39 UTC | |
by tye (Sage) on Nov 29, 2001 at 22:54 UTC | |
by traveler (Parson) on Nov 29, 2001 at 23:40 UTC | |
Re: fork()ing a large process
by Fastolfe (Vicar) on Nov 30, 2001 at 00:28 UTC | |
Re: fork()ing a large process
by Dogma (Pilgrim) on Nov 30, 2001 at 14:17 UTC |
Back to
Seekers of Perl Wisdom