- #!/bin/bash
- for(( i = 0; i < ${count}; i++ ))
- do
- {
- commands1
- }&
- done
- wait
- commands2
- #!bin/bash
- PRONUM=10 #进程个数
- tmpfile="$$.fifo" #临时生成管道文件
- mkfifo $tmpfile
- exec 6<>$tmpfile
- rm $tmpfile
- for(( i=0; i<$PRONUM; i++ ))
- do
- echo "init."
- done >&6
- for(( i = 0; i < ${count}; i++ ))
- do
- read line
- #echo $line
- {
- commands
- echo "line${i} finished."
- } >&6 &
- done <&6
- wait
本文介绍了一种使用 Bash 脚本并行执行命令的方法,通过创建临时管道文件来协调多个并发进程,提高了任务处理效率。适用于需要批量处理大量任务的场景。
314

被折叠的 条评论
为什么被折叠?



