首页 > 编程语言 > 详细

shell脚本实现多线程

时间:2016-05-15 12:40:25      阅读:286      评论:0      收藏:0      [点我收藏+]

1:

#!/bin/bash
for i in $(seq 1 1000)do
   ( Generating random numbers here , sorting  and outputting to file$i.txt ) &
   if (( $i % 10 == 0 )); then wait; fi # Limit to 10 concurrent subshells.
done
wait

2:

for ARG in  $*; do

    command $ARG &

    NPROC=$(($NPROC+1))

    if [ "$NPROC" -ge 4 ]; then

        wait

        NPROC=0

    fi

done


本文出自 “行者” 博客,请务必保留此出处http://223228686.blog.51cto.com/2222284/1773511

shell脚本实现多线程

原文:http://223228686.blog.51cto.com/2222284/1773511

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!