shell - How to write a background multiple sh run in a perl script? (tried several methods but all failed) -


i tried write background multiple sh run in perl script, below 3 tries:

for ( $i = 0; $i < @num - 1; $i++ ) {     $num1 = $num[ $i + 1 ] - 1;      `nohup sh ./tmpscript/matrixr.$num[$i]-$num1.sh &`     # don't know why not background run........just run 1 one , have wait......... } 

tried:

`sh *.sh &`      #wrong    ........just run 1 one , have wait......... 

also tried:

`cd tmpscript; file in *.sh; nohup sh \$file \&; done `;   #still wrong........just run 1 one , have wait......... 

they failed..could of , solve it? thanks!

p.s.: "``" these marks didn't displayed above..(seemed eaten stackoverflow, it's first time asking..)

so, given problem seems be:

invoke sh ./tmpscript/matrixr.$num[$i]-$num1.sh & multiple times in parallel.

my first thought it's worth having @ script, because perl can too.

however general case suggest using parallel::forkmanager:

use strict; use warnings;  use parallel::forkmanager; $manager = parallel::forkmanager->new(30);  ( $i = 0; $i < @num - 1; $i++ ) {     $num1 = $num[ $i + 1 ] - 1;      $manager->start , next;     exec("./tmpscript/matrixr.$num[$i]-$num1.sh >/dev/null")        or die($!); }  $manager->wait_all_children(); 

this has added advantage it'll parallelise 30 times, wait until sup processes complete before continuing. means don't denial-of-service server.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -