#!/usr/bin/perl
$grandi = getppid;
print "I'm the father $$, the grandfather is $grandi\n";
$pid = fork;
$firfat = getppid;
print "my first childs name is $pid\n" if $pid;
print "Hello I'm new born $$, my father is $firfat\n" unless $pid;
$pid2 = fork;
$secpar = getppid;
print "my second child is $pid2\n" if ($pid && $pid2);
print "my first child is $pid2\n" if (!$pid && $pid2);
print "Hello I'm new born $$, my father is $secpar\n" unless $pid2;
$pid3 = fork;
$sonfar = getppid;
print "my third child is $pid3\n" if ($pid && $pid2 && $pid3);
print "my second child is $pid3\n" if (!$pid && $pid2 && $pid3);
print "my first child is $pid3\n" if (!$pid2 && $pid3);
wait;
wait;
wait;
sleep (1) unless $pid3;
$parent = getppid;
$number = int(rand 1000);
print "$pid $pid2 $pid3 $number -->\n Sorry ,I'm process \#$$",
      " and my parent is $parent\n";

