I\'m trying to run some commands in paralel, in background, using bash. Here\'s what I\'m trying to do:
forloop {
//this part is actually written in perl
I don't know why nobody replied with the proper solution:
my @children;
for (...) {
...
my $child = fork;
exec "touch .file1.lock; cp bigfile1 /destination; rm .file1.lock;" if $child == 0;
push @children, $child;
}
# and if you want to wait for them to finish,
waitpid($_) for @children;
This causes Perl to spawn children to run each command, and allows you to wait for all the children to complete before proceeding.
By the way,
print `some command`
and
system "some command"
output the same contents to stdout, but the first has a higher overhead, as Perl has to capture all of "some command
"'s output