SPUG: Dying Children
Dan Ebert
mathin at mathin.com
Mon Sep 20 14:51:39 CDT 2004
Here's a snippet of what it was doing:
$SIG{CHLD} = \&REAPER;
$children++;
my $pid = fork
unless($pid) {
#do child stuff
exit;
}
ub REAPER {
my $stiff;
while(($stiff = waitpid(-1, &WNOHANG)) > 0) { $children--; }
$SIG{CHLD} = \&REAPER;
}
I changed the 'exit' to POSIX::_exit(0) and it is no longer delaying the
death.
Dan.
----------------------------------------------------------
Immigration is the sincerest form of flattery.
- Unknown
----------------------------------------------------------
On Mon, 20 Sep 2004, Jim Ludwig wrote:
> I assume you're keeping track of your child
> processes with a hash or something:
>
> my %file_writers = ();
>
> How is your child dying? Along the lines of the
> following?:
>
> $SIG{'CHLD'} = \&file_writer_died;
>
> # ...
>
> my $pid = fork();
> if ( $pid ) {
> # parent
> $file_writers{$pid} = 1; # or whatever
> }
> else {
> # child writes or whatever
> }
>
> # ...
>
> sub file_writer_died {
> local( $SIG{'CHLD'} ) = \&file_writer_died;
> my $pid = wait();
> delete( $file_writers{$pid} );
> }
>
> Or maybe your STDOUT output is buffered, and you
> want to force a flush immediately after every
> write/print?
>
> select(( select( STDOUT ), $| = 1 )[0] );
>
> Hope that's useful,
> jim
>
>
> >> Date: Mon, 20 Sep 2004 08:56:33 -0700 (PDT)
> >> From: Dan Ebert <mathin at mathin.com>
> >> To: <spug-list at mail.pm.org>
> >> Subject: SPUG: Dying Children
> >>
> >> I have a script which forks of a child process
> >> to write a file while the parent script goes on
> >> to collect the data for the next file. I'm
> >> keeping track of the number of file writing
> >> children so I don't have too many writers at
> >> one time. I have a debug print statement right
> >> before the exit in the child process:
> >>
> >> print "done writing file\n";
> >> exit;
> >>
> >> I am noticing that there are sometimes several
> >> seconds between the print and the actual death
> >> of the child. This is delaying the forking of
> >> the next child which is slowing the script
> >> down. Has anyone seen this before?
> >>
> >> Thanks,
> >>
> >> Dan.
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at mail.pm.org http://spugwiki.perlocity.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location Unknown
> WEB PAGE: http://www.seattleperl.org
>
More information about the spug-list
mailing list