LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-29-2007, 03:16 AM   #1
iceman_san
LQ Newbie
 
Registered: Aug 2007
Posts: 21

Rep: Reputation: 15
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
 
Old 08-29-2007, 07:41 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
You realize, don't you, that the exit(0) applies only to the child process and not to the parent?
 
Old 08-29-2007, 11:56 PM   #3
iceman_san
LQ Newbie
 
Registered: Aug 2007
Posts: 21

Original Poster
Rep: Reputation: 15
ok, but now how to overcome this problem, where should , i put th eexit statement,

thanks in advance


______________________________________________________
FREE as in FREEDOM thats LIFE
 
Old 08-30-2007, 09:36 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
After the main if(), ie where the parent code will go on successful fork()
 
Old 08-31-2007, 04:48 AM   #5
iceman_san
LQ Newbie
 
Registered: Aug 2007
Posts: 21

Original Poster
Rep: Reputation: 15
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
 
Old 09-01-2007, 10:51 AM   #6
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
malloc() in parent, free() in forked child nathan2225 Programming 5 11-11-2007 02:16 PM
kill process and its child in a shell dalmassoc Linux - Software 4 03-03-2006 01:57 AM
Kill windows process in Perl mnguyen Programming 2 01-04-2005 09:35 PM
When I kill parent process, child isn't killed BengeBoy Linux - Software 0 08-19-2004 04:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration