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