Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to call other Perl scripts in order to perform a contention test from with a main Perl script.

Something like this currently works:

system("perl 1.pl");
system("perl 2.pl");
exit;

However, I would like to kick these off as independent threads running at the same time.

I tried, based on my Google searches, doing something like this:

system(1, "perl 1.pl");
system(1, "perl 2.pl");
exit;

That doesn't work. The main script exists immediately, which is fine, but the underlying threads I want to spawn don't get kicked off. I was wondering if there was something else I have to do or if anyone else has done something like this.

Thanks for any help in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

use threads;
$thr1 = threads->create('msc', 'perl 1.pl');
$thr2 = threads->create('msc', 'perl 2.pl');

$thr1->join();
$thr2->join();

sub msc{ ## make system call
  system( @_ );
}

This will wait for both to finish executing before the it will exit. I'm guessing this is what you want from your original question, right? If not feel free to drop a comment and edit your post to explain it better, and I'll try again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...