in reply to Re^4: using system and exec in same script using child
in thread using system and exec in same script using child

this is what i wanted to do. i have a master script which need to do some processing of data and once it gets the proper information figured out, it need to launch another script which will log onto another machine and pull some data. Problem is that that script needs to run twice and in order to save time, i like to launch that script twice.. Now that i think about this for little bit perhaps i can do something like
== master script == doprocessing(); system("launchexternalscript"); gatherinfofromthoseinfo(); == externalscript == fork(); system("gotootherserverandgetinfo");
does this work?

Replies are listed 'Best First'.
Re^6: using system and exec in same script using child
by convenientstore (Pilgrim) on Jan 14, 2010 at 17:12 UTC
    mock up test is below.. it works but i am wondering if there is anything i am doing wrong or better ways to do things like this...
    [user1@myserver program]$ cat m_fork.pl #!/usr/bin/perl use warnings; use strict; for ( 1 .. 10 ) { print "how are you\n"; } system("/home/user1/program/test_fork.pl"); for ( 1 .. 10 ) { print "I love the results\n"; } [user1@myserver program]$ [user1@myserver program]$ [user1@myserver program]$ cat ./test_fork.pl #!/usr/bin/perl use warnings; use strict; my $child = fork (); die "can't fork: $!" unless defined $child; print "PID=$$\n"; if ( $child > 0 ) { #parent process print "Parent process: PID=$$, child=$child\n"; system("/home/user1/program/echo1.pl"); } else { my $ppid = getppid(); print "child process: PID=$$, parent=$ppid\n"; system("/home/user1/program/echo2.pl"); } [user1@myserver program]$ [user1@myserver program]$ [user1@myserver program]$ [user1@myserver program]$ cat ./echo1.pl #!/usr/bin/perl use warnings; use strict; for ( 1 .. 5 ) { print "this is echo1....\n"; sleep 10; } [user1@myserver program]$ [user1@myserver program]$ [user1@myserver program]$ cat ./echo2.pl #!/usr/bin/perl use warnings; use strict; for ( 1 .. 5 ) { print "this is echo2....\n"; sleep 10; } [user1@myserver program]$ ./m_fork.pl how are you how are you how are you how are you how are you how are you how are you how are you how are you how are you PID=2076 child process: PID=2076, parent=2075 PID=2075 Parent process: PID=2075, child=2076 this is echo1.... this is echo2.... this is echo1.... this is echo2.... this is echo1.... this is echo2.... this is echo1.... this is echo2.... this is echo1.... this is echo2.... I love the results I love the results I love the results I love the results I love the results I love the results I love the results I love the results I love the results I love the results