Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^6: using system and exec in same script using child

by convenientstore (Pilgrim)
on Jan 14, 2010 at 17:12 UTC ( [id://817440]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://817440]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found