Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute 3 external server scripts at once

Status
Not open for further replies.

Newbee21369

Programmer
Oct 13, 2004
30
US
I was wanting to execute no more than 3 external scripts simultanously.. would it be best to use the fork or the system command?

Thanks!
 
If you start scripts with "system" then the second script starts when the first finishes, and the third starts when the second finishes.
With "fork" all three scripts will start at the very same second.


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Fork is the correct way to go.

Here is some code another user posted when somebody else was having problems with fork.

Code:
use strict;
use warnings;

use Parallel::ForkManager;


my @sleepy_times=(3,5,2,8,1,6,4,7,9,10);

my $pm = new Parallel::ForkManager(10);

foreach my $sleepy_time (@sleepy_times) {

$pm->start and next; # do the fork

print "sleeping for $sleepy_time seconds\n"; 
sleep $sleepy_time;
print "done ($sleepy_time)\n";

$pm->finish; # do the exit in the child process

}

$pm->wait_all_children;


Michael Libeson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top