Ask a Question related to PERL Miscellaneous, Design and Development.
-
Monika Talwar #1
parenp process controlling child
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 ...
Monika Talwar Guest
-
#37998 [Asn->Fbk]: Parent process lost MySQLi connection after child process gone
ID: 37998 Updated by: tony2001@php.net Reported By: dbs at is dot ua -Status: Assigned +Status: ... -
How to get the child process pid ?
Dear all , I would like to find an (easy) way to automatically get the process id of the latest child process of a user per tty. (the process... -
Beginners question : controlling an child
I have an 'beginners" question..... I use the following line tot rotate my 3dmax model member("Filename").model("car").rotate(0,0,1,#self) ... -
How to impersonate the child process of an ASP.NET application
I am running a web service on IIS 6.0, impersonation is set to true, so my web service can access resources depending on the client's privileges,... -
Forking child process with WWW::Automate
Hi all, I'm attempting to automate a login to a web server with WWW::Automate and then to continue navigating through the website. I've hit a... -
Anno Siegel #2
Re: parenp process controlling child
Monika Talwar <monikatalwar@hotmail.com> wrote in comp.lang.perl.misc:
Signal 9 is a little radical. It should only be used when a process> 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 ; }
> }
can't be killed by other means. I'd use a TERM signal.
I don't think this loop times what you want to time. You are waiting> 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";
> }
> }
for this child process to accumulate two seconds of CPU time. Depending
on system load, this could take any amount of real time from two seconds
upwards. I expect you actually want to wait for two seconds real time.
Also, what you have there is a busy loop -- the process will continuously
be actively querying its CPU time and produce system load.
To repair both, use the sleep() command (see perldoc -f sleep).
You don't need a separate process to establish a time limit for a> 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.
process. Simply set an alarm timer (perldoc -f alarm). It will
kill your process after a set time.
If you need to do things after the alarm timer fires, there is
"perldoc -q 'slow event'" which shows how to catch the timer
signal.
You don't need a separate process for the timeout. Set an alarm timer> bothchilderen and paren should terminate once any of the child
> terminates....
>
> Can anyone suggest me better way to implement this ??
in the working child process. Your use of "wait" to let the parent die
with the kid looks fine (I didn't run your progeam). It will be
simplified when there is only one process to wait for.
Anno
Anno Siegel Guest



Reply With Quote

