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

Parallel::ForkManager and system "command",@args;

by strredwolf (Chaplain)
on Jan 13, 2006 at 16:12 UTC ( #523018=perlquestion: print w/ replies, xml ) Need Help??
strredwolf has asked for the wisdom of the Perl Monks concerning the following question:

Question -- is it safe to use Parallel::ForkManager with system? I want to fire off x-amount of one program and track it (similar to what make -j4 does with gcc). This is on a Linux and a FreeBSD system, so Windows fork emulation is a non-issue.

--
$Stalag99{"URL"}="http://stalag99.net";

Comment on Parallel::ForkManager and system "command",@args;
Re: Parallel::ForkManager and system "command",@args;
by tirwhan (Abbot) on Jan 13, 2006 at 16:27 UTC

    You mean fork off x children and then call an external process from each of them with system()? That may not be the most efficient way of solving the task at hand (depending on what exactly your task is), but I can't see any problems with this approach. Be sure to pass command arguments to system in an array so that you don't spawn a shell for every program you start.


    There are ten types of people: those that understand binary and those that don't.
Re: Parallel::ForkManager and system "command",@args;
by ikegami (Pope) on Jan 13, 2006 at 16:57 UTC

    Are you sure you want to use system (which consists of a fork, an exec and a waitpid) instead of exec? If you need to return to the Perl script, great. If not, use exec. As far as I can tell, both will work.

    Update: On second thought, you need to call finish, so exec is out. Looking at the module's guts, system should be ok, since the module doesn't care what the children do, as long as they call finish when they are done.

    Update: After further digging, it's doesn't appear necessary to call finish in the child after all, since all it does is call exit. That means exec would work as well!

Re: Parallel::ForkManager and system "command",@args;
by salva (Monsignor) on Jan 13, 2006 at 18:34 UTC
    instead of Parallel::ForkManager you can use Proc::Queue:
    use Proc::Queue size => 5, qw(system_back); for my $args (@args) { system_back $cmd, @{$args}; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2014-07-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls