증가하는 수면 시간에 bash 루프?


1

나는 bash에서 while 루프를 이렇게하고 싶습니다 :

while read i
do
    ~/bin/submit_job $i
    sleep N
done

하지만 N in sleep N 처음에는 짧을 것이고 처음 몇 번의 반복 후에 점진적으로 증가 할 것입니다. 처음 8 초 동안 1 초가 걸린 후 다음과 같이 초 단위로 증가합니다.

 1 1 1 1 1 1 1 1 (first 8 iterations)
 2 2 2 2 2 2 2 2 
 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 
 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 
 ...

어떤 아이디어?

답변:


3

테스트 및 작업 :

#/bin/bash
sleeptime=1
countsleeps=1
maxcount=8

while read i
do
    ~/bin/submit_job $i
    sleep $sleeptime
    let countsleeps++
    if ((countsleeps>maxcount))
    then
        countsleeps=1
        let sleeptime*=2
        if ((sleeptime>2)) ; then let maxcount*=2 ; fi
    fi
done
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.