2012-06-19 158 views

回答

1

当你用脚本的文件夹中运行这个bash脚本/命令:

for var in $(ls *.pl) 
do 
    $var & 
    # 5 simultaneous jobs 
    while test "$(jobs |wc -l)" -gt 4 
    do 
     sleep 1 
    done 
done 

这依赖于你没有其它后台任务运行,通过写“工作”在命令行上进行测试。

+0

我后来得知您可以使用xargs来运行多个并行作业。使用4个进程同时gzip文件: 'ls * .pl | xargs -n1 -P4 gzip' – Pylinux

2

你可以使用nohup前5个脚本的任何解决方案?让第五个脚本写入已完成并继续的某个文件。

0
You can write sth like below. It's pseudo code. 

#!/bin/ksh 

dir=$1 
count=0 
for script in $1/* 
    do 
    count++ 
    $i & 
    add the pid to pidList array 
    if(count==5){ 
    while(waitforProcessComplete(pidList){ 
    } 
    } 

    done 
0

我宁愿GNU并行。这很容易和有趣 - 而且documentation带有许多简洁的例子。

最大的优点是:您不必编写任何代码或Makefile来运行脚本。示例:

# create the example scripts: 
mkdir scripts 
for i in {1..50}; do {echo '#!/bin/sh'; echo "echo $i"; echo "sleep 1" } > scripts/s$i.sh; done 

# use parallel to run all these scripts, 5 at a time: 
parallel -j 5 ::: scripts/*.sh 
相关问题