LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2006, 09:56 PM   #1
danfou
Member
 
Registered: Nov 2006
Posts: 46

Rep: Reputation: 15
question about perl's exec


Here's part of my perl program:

if (my $pid = fork) {
waitpid($pid, 0);
print "end exec\n";
}
else {
defined($pid) or die "fork: $!";
print "start exec\n";
exec "ssh -f $opt_s ping -c 10 $opt_d > pingout";
}

I want to do other things after the ping ends.
But it turns out that the parent proc continue to do the following command while ping is still running.

Can you tell me how to write the correct program to such thing?
Thanks a lot.
 
Old 11-05-2006, 10:57 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
From the Camel book:
exec: This fn terminates the currently running Perl script by executing another proggram in place of itself (!)
My exclamation...
Once you've forked, you now have 2 perl procs. You don't need to actually invoke exec.
If you want to run an external prog, try the system() fn in the child proc.

See here http://perldoc.perl.org/functions/fork.html & http://perldoc.perl.org/functions/exec.html
 
  


Reply

Tags
code



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
Perl's LWP to Python?? chutsu Programming 3 06-05-2006 12:55 PM
exec cmd=perl... work but exec cgi doenst crions Slackware 5 12-09-2005 12:17 PM
perl's system() command paul_mat Linux - Software 3 11-21-2005 01:37 AM
exec question spank Programming 2 12-26-2004 04:30 PM
find -exec question eantoranz Linux - General 1 06-26-2004 10:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:37 PM.

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