binghai03 发表于 2018-8-22 10:57:53

shell下的多进程实现

#!/bin/bash  
#允许的进程数
  
THREAD_NUM=${2:-10}
  
#定义描述符为9的管道
  
mkfifo tmp
  
exec 9tmp
  
#预先写入指定数量的换行符,一个换行符代表一个进程
  
for ((i=0;i&9
  
done
  

  
if [ $# -lt 1 ] ;then
  
      echo "The parameters you enter is not correct !";
  
      exit -1;
  
fi
  

  
date
  
while read line
  
do
  
{
  
    #进程控制
  
    read -u 9
  
    {
  
      isok=`curl -I -o /dev/null -s -w %{http_code} $line`
  
      if [ "$isok" = "200" ]; then
  
            echo $line "OK"
  
      else
  
            echo $line "no"
  
      fi
  
      sleep 1
  
      echo -ne "\n" 1>&9
  
    }&
  
}
  
done < $1
  
wait
  
echo "执行结束"
  
date
  
rm tmp


页: [1]
查看完整版本: shell下的多进程实现