LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to kill a forked child-process in perl (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-kill-a-forked-child-process-in-perl-580632/)

iceman_san 08-29-2007 03:16 AM

how to kill a forked child-process in perl
 
hi,

can any one help me to with this problem ,

my $pid=fork();
die "Cannot fork: \n" if (! defined $pid);
if (! $pid) {
# Only the child does this
$sys = system("/usr/bin/firefox localhost:8066 >/dev/null");
if($sys!='0'){
print RED, "Sorry the web page could not be loaded" , RESET;
exit(0);
}
}

when i execute the above snippet of code , the program displays,
print statement and gets hanged m without returning my terminal, help plsssssss

regards,
ice_man

---------------------------------------------------------------
FREE as in FREEDOM thats LIFE

wjevans_7d1@yahoo.co 08-29-2007 07:41 AM

You realize, don't you, that the exit(0) applies only to the child process and not to the parent?

iceman_san 08-29-2007 11:56 PM

ok, but now how to overcome this problem, where should , i put th eexit statement,

thanks in advance


______________________________________________________
FREE as in FREEDOM thats LIFE

chrism01 08-30-2007 09:36 PM

After the main if(), ie where the parent code will go on successful fork()

iceman_san 08-31-2007 04:48 AM

sorry id did not work , i tried using wxit after the main if() block , but it was vain , any suggestiond ,please


_________________________________________
FREE as in FREEDOM thats LIFE

wjevans_7d1@yahoo.co 09-01-2007 10:51 AM

Try writing a simple Perl script whose only job is to fork. Put a print statement in the child code saying "running the child code", and print also the current pid. Put another print statement in the parent code saying "running the parent code", and print also the current pid.

The pid is stored in special variable [BOLD]$$[/BOLD]

Then run the program. If it does what you expect, then see how it differs from the program which is troubling you. If it doesn't do what you expect, post that tiny program here (the entire tiny program).


All times are GMT -5. The time now is 11:18 PM.