Bash control task concurrency script

Source: Internet
Author: User

Bash controls the number of concurrent jobs. The script uses bash to control the number of concurrent jobs. 01 #! /Bin/bash02 #03 04 CMDS [1] = "echo $ USER '01 begin' & sleep 6 & echo $ USER '01 end'" 05 CMDS [2] = "echo $ USER '02 in in' & sleep 3 & echo $ user' 02 end'" 06 CMDS [3] = "echo $ USER '03 in in' & sleep 7 & echo $ USER '03 end' "07 CMDS [4] =" echo $ user' 04 In in '& sleep 4 & echo $ user' 04 end' "08 CMDS [5] = "echo $ USER '05 in in' & sleep 2 & echo $ USER '05 end'" 09 CMDS [6] = "echo $ USER '06 in in' & sleep 5 & echo $ USER '06 end' "10 11N =$ {# CMDS [@]} 12 13MAX = 314 PIDS = ''15for I in $ (seq $ N) 16do17 while [1-gt 0] 18 do19 C = 020 pids = ''21 for PID in $ PIDS22 do23 ps $ PID>/dev/null 2>/dev/null24 if [$? -Eq 0] 25 then26 pids = "$ pids $ PID" 27 (C = C + 1 )) 28 fi29 done30 PIDS = $ pids31 32 [$ C-lt $ MAX] & break33 sleep 134 done35 36 # echo $ I $ {CMDS [$ I]} 37 CMD =$ {CMDS [$ I]} 38 bash-c "$ CMD" & 39 PIDS = "$ PIDS $! "40done41 42 wait

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.