How to launch many programs sequentially without being block?
In unix system
I have a directory called program_sets , and in the program_sets , there exists 8 directory and in each directory they have a program called A.pl
I want to launch and run 8 A.pl programs in the same time , but when I launch the first program , the procedure will be block until the first program call is finish . How can I solve this problems?
here is my code
#!/usr/bin/perl opendir(Programs,"./program_sets"); @Each_names = readdir(Programs); shift(@Each_names); shift(@Each_names); for($i=0;$i<=$#Each_names;$i++) { `perl ./program_sets/$Each_names[$i]/A.pl`; }
thanks
Answers
Run them in the background with &, just like you would from the shell.
for($i=0;$i<=$#Each_names;$i++) { system("perl ./program_sets/$Each_names[$i]/A.pl >/dev/null 2>&1 &"); }
Also, backticks should be used when you're assigning the output to a variable. Use system() to run a command without saving the output.