Bash脚本之多线程处理
生活随笔
收集整理的這篇文章主要介紹了
Bash脚本之多线程处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
在bash中并沒有線程的概念,我們可以用多進程來模擬多線程的操作來達到同樣的效果
示例代碼
#!/bin/bash# thread number can modify if needed THREAD=10 ROOTDIR="$(pwd)" TMP_FIFO="/tmp/$.fifo"#cannot del here. this is thread control mkfifo "${TMP_FIFO}" exec 6<>"${TMP_FIFO}" rm ${TMP_FIFO}needToDo(){ #do something her you need mutithread do }#cannot del here. this is thread control for ((i=0;i<${THREAD};i++)); doecho done >&6while ((1)) #some control doread -u6{needToDoecho >&6}& done wait exec 6>&- exit 0總結
以上是生活随笔為你收集整理的Bash脚本之多线程处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android性能优化之启动速度优化
- 下一篇: illustrator内描边