while(1)
{
my @children;
defined (my $pid = fork) or die "Cannot fork: $!\n";
if ($pid)
{
# Parent Process...
push(@children, $pid);
wait();
my $ret = $?;
if ($ret)
{
warn("Abnormal child exit: $!\n");
$daemon = undef;
last;
}
}
else
{
# Child Process...
exit(0);
}
while (scalar(@children))
{
wait();
my $ret = $?;
shift(@children);
if ($ret)
{
warn("Abnormal child exit: $!\n");
$daemon = undef;
}
}
}
continue
{
last unless $daemon;
sleep(10);
}
Our highest priority is to satisfy the customer through early and continuous delivery of valuable and working software.
Friday, December 21, 2007
Perl - fork() example
Here is a small example which demonstrate fork() implementation in PERL.
Subscribe to:
Post Comments (Atom)
Keep up the good work. Merry Christmas & Happy New Year!
ReplyDeleteWell, this is useless as an example. What is it supposed to do? Where is the description?
ReplyDeletewhy do we wait for child processed later again?
ReplyDeleteI agree. This is a useless example
ReplyDeleteDumb"est" blog ever seen
ReplyDelete