Hello monks,
I wanted to launch 2 external programs from perl script at the sametime and problem I ran into is that when parent and child is done running 2 external program, subsequent lines gets executed twice.( I used system command ). since I wanted to just run subsequent command once , i tried using system(parent) and exec(for child).. it looks like program worked but not sure if this is the right way to do things like this... Please advise.
ps:I am not sure about wait command as when i monitor the process, they seem to perfectly go away without wait command
thank you.
use warnings;
use strict;
print "PID=$$\n";
my $child = fork();
die "Can't fork: $!" unless defined $child;
sub si {
my $ar = shift;
print "ar is $ar\n";
}
if ( $child > '0' ) { #parent process
print "Parent process: PID=$$, chid=$child\n";
system("/root/program/parent_pro.pl");
} else { #child process
my $ppid = getppid();
print "Child process: PID=$$, parent=$ppid\n";
#system("echo this is child");
exec("/root/program/child_pro.pl");
}
print "hi how are you\n";
print "fine i am doing good\n";
si("MJ");
si("JP");
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.