bash while loop threading

后端 未结 3 1043
太阳男子
太阳男子 2021-02-15 15:47

i have a while loop reading lines from a $hosts

while read line
do
    ip=$line
    check
done < $hosts

my question is can I us

3条回答
  •  春和景丽
    2021-02-15 16:00

    You can start multiple processes, each calling the function check and wait for them to finish.

    while read line 
    do 
      ip=$line
      check &
    done < $hosts
    wait # wait for all child processes to finish
    

    Whether this increases the speed depends on available processors and the function check's implementation. You have to ensure there's no data dependency in check between iterations.

提交回复
热议问题