任务:运行由3-5个命令组成的块(并行/后台).
示例块:
示例块:
dd if=/dev/urandom of=/mnt/1/x bs=1024 count=1024000000 & dd if=/dev/urandom of=/mnt/2/x bs=1024 count=1024000000 & dd if=/dev/urandom of=/mnt/3/x bs=1024 count=1024000000 &
完成后,下一个块应该运行.
我想,这可以通过锁定文件来完成:
task1.sh:
real_task1 real_param1 ; rm /var/lock/myscript/task1.lock
task2.sh:
real_task2 real_param1 ; rm /var/lock/myscript/task2.lock
…
taskgen.sh:
# loop # while directory isn't empty - wait... gen_tasks.pl # build task files from some queue for i in 1 2 3; do touch /var/lock/myscript/task$i.lock ; done ./task1.sh & ./task2.sh & ./task3.sh & # if task1.sh doesn't exits then exit,else loop waits for files to be deleted
检查目录是否为空的一些方法可以找到here,不确定使用哪个;
问题:有没有更好的方法来实现这个?
附:可能的状态报告方法:
command && report_good_state.sh taskid ; report_state_done.sh taskid; rm /var/lock/myscript/taskN.lock
这正是07000的设计目标,因此我强烈建议您使用它.特别是,看看它运行它
as a semaphore:
for i in {1..4} do echo running $i sem -j3 df dd if=/dev/urandom of=/mnt/$i/x bs=1024 count=1024000000 ";" echo done done # sem --wait waits until all jobs are done. sem --wait