Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by convenientstore (Pilgrim)
on Jan 11, 2010 at 22:33 UTC ( [id://816799]=note: print w/replies, xml ) Need Help??


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

so, can regular perl program have multiple sub working at sametime? Like displaying moving dots while calculating or simulatenaously launching two external program from perl script.. is that not possible? What I thought of child process is wrong as it's running the same program I am running twice.. i need ways(or at least clue) on how to do above things without running full program of it's own.
  • Comment on Re^3: using system and exec in same script using child

Replies are listed 'Best First'.
Re^4: using system and exec in same script using child
by BrowserUk (Patriarch) on Jan 11, 2010 at 23:49 UTC
    can regular perl program have multiple sub working at sametime?

    Sure can:

    use threads; async{ print "I'm doing this over here while he's...", sleep 1 while 1 }; print "doing that over there, while...", sleep 1 while 1; I'm doing this over here while he's... 1.001 doing that over there, while... 1.001 I'm doing this over here while he's... 0.999772 doing that over there, while... 0.999429 I'm doing this over here while he's... 0.999626 doing that over there, while... 0.99956 I'm doing this over here while he's... 0.999724 doing that over there, while... 0.999355 Terminating on signal SIGINT(2)

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      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?
        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
Re^4: using system and exec in same script using child
by ikegami (Patriarch) on Jan 11, 2010 at 22:49 UTC

    so, can regular perl program have multiple sub working at sametime?

    Yes, if threads are used.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-25 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found