∗∗∗∗∗
for $p (@a){
system("/path/to/file.sh $p&");
}
页: 1
∗∗∗∗∗
for $p (@a){
system("/path/to/file.sh $p&");
}
页: 1
Us/ex/wa
my @a = (1, 2, 3);
for my $p (@a) {
my $pid = fork();
if ($pid == -1) {
die;
} elsif ($pid == 0) {
exec /bin/sleep , $p or die;
}
}
while (wait() != -1) {}
print "Done
";
< >>,>>,>,<>>>,>,>,>,>,>,>,>,>,>,>,>,>,>,>,<>,>,>,>,<>,>,>,>
纽约总部
#!/bin/bash
$*
touch /tmp/$2.$PPID
——————
for my $p (@a){
system("/path/to/wrapper.sh /path/to/file.sh $p &");
}
while (@a) {
delete $a[0] if -f "/tmp/$a[0].$$";
}
∗∗∗∗
my @pids;
for my $p (@a) {
die "could not fork" unless defined(my $pid = fork);
unless ($pid) { #child execs
exec "/path/to/file.sh", $p;
die "exec of file.sh failed";
}
push @pids, $pid; #parent stores children s pids
}
#wait for all children to finish
for my $pid (@pids) {
waitpid $pid, 0;
}
<0> > > > : >;<>;>;<>;>;>;<>;>;>;>;>;>;>;>;>;>; 页: 1
<> > > > > > > > > > > > >