Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

I want to launch two subroutines at once

by juo (Curate)
on Feb 18, 2003 at 15:17 UTC ( #236270=perlquestion: print w/ replies, xml ) Need Help??
juo has asked for the wisdom of the Perl Monks concerning the following question:

Does anybody know how it is possible to run two subroutines at once. One routine is a process that runs for a long time. The other routine is an activity bar that has to run as long as the other process is not completed. So the only way to do that is by launching both processes at the same time.

Comment on I want to launch two subroutines at once
Re: I want to launch two subroutines at once
by broquaint (Abbot) on Feb 18, 2003 at 15:21 UTC
    Sounds like a perfect situation for fork() and further to that Parralel::ForkManager. Or if you've got perl5.8.0 you've also got the option of using threads.
    HTH

    _________
    broquaint

Re: I want to launch two subroutines at once
by tommyw (Hermit) on Feb 18, 2003 at 15:23 UTC

    I don't understand the context of the question: where's this activity bar going to be displayed? You could run two separate processes by using fork, but is it not easier to have one process which runs for a very long time, and occasionally maintains an activity bar? This avoids the need to have two processes.

    --
    Tommy
    Too stupid to live.
    Too stubborn to die.

Re: I want to launch two subroutines at once
by integral (Hermit) on Feb 18, 2003 at 15:26 UTC

    The solution I can immediately think of is to create the activity bar (the 'monitoring process') first, and have it create the other as the child so that it knows its pid and can establish ipc structures before/after the fork. Something like the code below could be used.

    pipe my $read, my $write; if (my $pid = fork()) { # monitor process close $write; read $read and update progress } else { close $read; while (1) { do stuff; print $write "status"; } }
    This code does only creates the one other process however, so if you really want two subprocesses created you have to wrap it in another fork.

    --
    integral, resident of freenode's #perl
    

      I have tried this code on Perl 5.6 - Windows 2000 and it generates Dr watson. Looks like Fork is not made for Windows 2000.

Re: I want to launch two subroutines at once
by Abigail-II (Bishop) on Feb 19, 2003 at 00:16 UTC
Re: I want to launch two subroutines at once
by adrianh (Chancellor) on Feb 19, 2003 at 10:18 UTC

    Another alternative would be to change, if possible, the way the process work.

    Instead of doing everything in one go change it to do it in smaller chunks. Then you can use something like POE to multi-task the two processes.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://236270]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-12-28 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls