shell的單、多、控制進程

來源:互聯網
上載者:User

標籤: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的單、多、控制進程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.