標籤:shell time expr wait
shell的單、多、控制進程的使用方法一、100個任務使用200秒(普通完成)cat process2.sh #!/bin/bashfunction aaa () { start=`date "+%s"` for ((i=1;i<=100;i++)) do echo test;sleep 2 doneend=`date "+%s"` echo "time:`expr $end - $start`" } aaa exit 0================執行結果=================time:200real 3m20.338suser 0m0.032ssys 0m0.008s 二、100個任務使用2秒(非控制進程完成任務)cat process1.sh #!/bin/bashfunction aaa () { start=`date "+%s"` for ((i=1;i<=100;i++)) do ( echo test;sleep 2 )&donewait end=`date "+%s"` echo "time:`expr $end - $start`" } aaa exit 0================執行結果=================time bash process1.shtime:2real 0m2.259suser 0m0.008ssys 0m0.020s三、100個任務使用20秒(控制進程完成任務,生產環境使用)cat process.shfunction aaa () { start=`date "+%s"` for ((i=1;i<=100;i++)) do ( echo 111;sleep 2 )& [[ $i%10 -eq 0 ]] && wait donewait end=`date "+%s"` echo "time:`expr $end - $start`" } aaaexit 0================執行結果=================time bash process.shtime:20real 0m20.376suser 0m0.000ssys 0m0.032s
本文出自 “7928217” 部落格,請務必保留此出處http://7938217.blog.51cto.com/7928217/1653487
shell的單、多、控制進程