Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by strredwolf (Chaplain)
on Jan 13, 2006 at 16:12 UTC ( [id://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";

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 (Patriarch) 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found