Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use POSIX qw(:errno_h); use POSIX qw(:sys_wait_h); $SIG{CHLD} = "IGNORE"; my ($child, $script, $cleanup, $time); &create_child; sleep($time); &reaper; sub create_child { unless($child = fork()) { die "Cannot fork: $!" unless defined $child; exec($script); } $child++; } # Some values are from get_args sub not shown sub reaper { if(kill 0 => $child) { print "Child timed out, sending signal 15\n"; kill 15, $child; exec($cleanup); } elsif ($! == EPERM) { print "Child has changed its UID\n"; } elsif ($! == ESRCH) { print "Child is already dead\n"; } else { warn "Could not check child's PID: $!\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Child PID?
by Juerd (Abbot) on Jun 06, 2002 at 21:06 UTC | |
by Anonymous Monk on Jun 06, 2002 at 23:47 UTC | |
by perigeeV (Hermit) on Jun 07, 2002 at 00:28 UTC | |
by Abigail-II (Bishop) on Jun 07, 2002 at 11:33 UTC | |
|
Re: Child PID?
by jsprat (Curate) on Jun 06, 2002 at 21:02 UTC |