shell 脚本并发控制

3050阅读 0评论2013-09-26 sunjiangang-ok
分类:Python/Ruby

直接上脚本和运行结果
  1. #!/bin/bash
  2. function a_sub {
  3.         sleep 2
  4. }

  5. tmp_fifofile="/tmp/$$.fifo"
  6. mkfifo $tmp_fifofile
  7. exec 6<>$tmp_fifofile
  8. rm $tmp_fifofile

  9. thread=15
  10. for ((i=0;i<$thread;i++));do
  11.         echo
  12. done >&6

  13. for ((i=0;i<50;i++));do
  14.         read -u6
  15.         {
  16.                 a_sub && {
  17.                         echo "a_sub is finished"
  18.                 } || {
  19.                         echo "sub error"
  20.                 }
  21.                 echo >&6
  22.         }&
  23. done
  24. wait
  25. exec 6>&-
  26. exit 0
time bash xxx.bash
...
...
...


real    0m8.010s
user    0m0.014s
sys     0m0.054s
上一篇:vim ide 环境搭建
下一篇:wireshark 过滤规则