Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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.


  • Comment on Parallel::ForkManager and system "command",@args;

Replies are listed 'Best First'.
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 (Canon) 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?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2021-02-25 02:27 GMT
Find Nodes?
    Voting Booth?

    No recent polls found