M
Monika Talwar
How can parent process control a child??
I tried to kill the child, but the code didn;t worked to my
expectation.
Actually i wrote the following code -
# fork first child
if(defined($pid= fork))
{
print "1) pare $pid \n\n";
if($pid) ## If parent process then fork another child to start
timer
{ # fork new child
my $child_pid = fork;
# if parent process then wait for one of the child to terminate
if($child_pid)
{ # wait for children
my $terminated_id = wait;
# kill the still active child
if($terminated_id == $pid)
{ kill 9, $child_pid; }
else
{ kill 9, $pid ; }
}
else ## child that start the timer
{
print "2 start child $child_pid \n";
my ($luser_time,$lsys_time,$lcu_time,$lcs_time) = times;
LOOP_ON_TIMER :
print "\nLOOOOOOOP
($luser_time,$lsys_time,$lcu_time,$lcs_time)\n\n";
($luser_time,$lsys_time,$lcu_time,$lcs_time) = times;
goto LOOP_ON_TIMER if ($luser_time <= 2);
print "\t\t 2) child $pid exiting\n\n";
}
}
else # if first child, then fire the test case
{ print "1 start child $pid";
&run_test_case($i);
$flag =1;
}
}
Here parent forks two childeren,- One childeren is suppose to simulate
some system task ..
another child works as watch dog.
bothchilderen and paren should terminate once any of the child
terminates....
Can anyone suggest me better way to implement this ??
Thanks in advance ...
I tried to kill the child, but the code didn;t worked to my
expectation.
Actually i wrote the following code -
# fork first child
if(defined($pid= fork))
{
print "1) pare $pid \n\n";
if($pid) ## If parent process then fork another child to start
timer
{ # fork new child
my $child_pid = fork;
# if parent process then wait for one of the child to terminate
if($child_pid)
{ # wait for children
my $terminated_id = wait;
# kill the still active child
if($terminated_id == $pid)
{ kill 9, $child_pid; }
else
{ kill 9, $pid ; }
}
else ## child that start the timer
{
print "2 start child $child_pid \n";
my ($luser_time,$lsys_time,$lcu_time,$lcs_time) = times;
LOOP_ON_TIMER :
print "\nLOOOOOOOP
($luser_time,$lsys_time,$lcu_time,$lcs_time)\n\n";
($luser_time,$lsys_time,$lcu_time,$lcs_time) = times;
goto LOOP_ON_TIMER if ($luser_time <= 2);
print "\t\t 2) child $pid exiting\n\n";
}
}
else # if first child, then fire the test case
{ print "1 start child $pid";
&run_test_case($i);
$flag =1;
}
}
Here parent forks two childeren,- One childeren is suppose to simulate
some system task ..
another child works as watch dog.
bothchilderen and paren should terminate once any of the child
terminates....
Can anyone suggest me better way to implement this ??
Thanks in advance ...