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.


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);
}

6 comments:

  1. Keep up the good work. Merry Christmas & Happy New Year!

    ReplyDelete
  2. Hi 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.

    ReplyDelete
  3. Well, this is useless as an example. What is it supposed to do? Where is the description?

    ReplyDelete
  4. why do we wait for child processed later again?

    ReplyDelete
  5. I agree. This is a useless example

    ReplyDelete
  6. Dumb"est" blog ever seen

    ReplyDelete