Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 在shell中批量启动多个计算_Linux_Shell_Ksh - Fatal编程技术网

Linux 在shell中批量启动多个计算

Linux 在shell中批量启动多个计算,linux,shell,ksh,Linux,Shell,Ksh,我有16个计算要做,我想批量启动它,以便同时使用我机器的16个内核。 我想做这样一个shell脚本: #!/bin/ksh for i in `seq 16` do cd directory$i <batch command> done 可能吗 你可以。您只需确保它们作为后台任务运行,例如: #!/bin/ksh for i in `seq 16` do cd directory$i <batch command> & done 无需使用bac

我有16个计算要做,我想批量启动它,以便同时使用我机器的16个内核。 我想做这样一个shell脚本:

#!/bin/ksh
for i in `seq 16`
do
  cd directory$i
  <batch command>
done
可能吗

你可以。您只需确保它们作为后台任务运行,例如:

#!/bin/ksh
for i in `seq 16`
do
  cd directory$i
  <batch command> &
done

无需使用backticks外部命令

#!/bin/ksh
for d in  dir{1..16}; do
    echo $d &
done
wait
echo done
顺便说一句,schellcheck.net会说:

Use $(..) instead of legacy `..`

是否需要执行16等待命令?在人工等待中,我有:等待[n…]等待每个指定进程并返回其终止状态。如果未给定n,则等待所有当前活动的子进程,返回状态为零。所以只需要在脚本结束时等待1次就可以了吗?@rudy:我不确定ksh的情况,但你刚才的测试似乎是对的。bash和ksh都将等待所有当前活动的子级。当然,如果你有其他的孩子不是16岁的那一组,这可能会带来另一个问题。如果是这样,您可能需要考虑存储PID和使用显式等待。
Use $(..) instead of legacy `..`