Single, multiple, and controlled process of the shell

Source: Internet
Author: User

Tag: Shell time expr wait

Shell single, multi, control process use method one, 100 tasks using 200 seconds (normal completion) 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================ Execution Results =================time:200real    3m20.338suser     0m0.032ssys     0m0.008s   two, 100 tasks using 2 seconds (non-control process to complete the task) 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============= = = = Execution result =================time bash process1.shtime:2real    0m2.259suser     0m0.008ssys&Nbsp;    0m0.020s Three, 100 tasks use 20 seconds (Control process complete task, production environment use) 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================ Execution Results =================time bash process.shtime:20real     0m20.376suser    0m0.000ssys     0m0.032s


This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1653487

Single, multiple, and controlled process of the shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.