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);
}
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!
ReplyDeleteHi Nice Blog .In my point of view seo india is designing, writing, coding and maintaining our web site easily. It is a good chance to appear our web page at the top of search engine queries for the selected keywords and key phrases.
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?
ReplyDelete