Executing multiple System Commands parallel

T

Tobias Glasow

Hi all,

i want to execute multiple system commands at the same time out of a perl
script. i tried exec, system an qx, but all seem to execute on command by
one, after the preceding has finished.

any ideas how to do this in perl?

Tobias
 
G

Gregory Toomey

Tobias said:
Hi all,

i want to execute multiple system commands at the same time out of a perl
script. i tried exec, system an qx, but all seem to execute on command by
one, after the preceding has finished.

any ideas how to do this in perl?

Tobias

system("/path/to/command1 &");
system("/path/to/command2 &");
system("/path/to/command3 &");
etc

gtoomey
 
J

Jürgen Exner

Tobias said:
i want to execute multiple system commands at the same time out of a
perl script. i tried exec, system an qx, but all seem to execute on
command by one, after the preceding has finished.

"At the same time" as in "in parallel"?
Either use fork() to create multiple processes and each process launches its
own system() or use whatever method your OS or shell (you didn't tell us)
provides to launch each individual external command in the background, such
that the next one will be started by the shell/OS before the preceeding
commands are finished.

jue
 
G

Graham Wood

Tobias said:
Hi all,

i want to execute multiple system commands at the same time out of a perl
script. i tried exec, system an qx, but all seem to execute on command by
one, after the preceding has finished.

any ideas how to do this in perl?

Tobias

If you're on Windows, you can use the Win32::process module to create
"forked" processes. If using ActiveState perl you get this for free and
you don't even have to install it. "perldoc Win32::process" will show
you the docs. Last time I checked fork() didn't work very well on
Windows (it might now). If you're on Unix fork() is the man for the job.

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top