Why do sleep & wait in bash?

后端 未结 2 1783
终归单人心
终归单人心 2021-02-01 06:57

I\'m having trouble understanding the startup commands for the services in this docker-compose.yml. The two relevant lines from the .yml are:

command: \"/bin/sh          


        
2条回答
  •  独厮守ぢ
    2021-02-01 07:18

    The only reason I see:

    If you killall -INT sleep, this won't affect main script.

    Try this:

    while true ;do sleep 12; echo yes;done
    

    Then send a Interrupt signal:

    killall -INT sleep
    

    This will break the job!

    Try now

    while true ;do sleep 12 & wait $! ; echo yes;done
    

    Then again:

    killall -INT sleep
    

    Job won't break!

    Sample output, hitting killall -INT sleep from another window:

    user@myhost:~$ while true ;do sleep 12; echo yes;done
    break
    
    user@myhost:~$ while true ;do sleep 12 & wait $! ; echo yes;done
    [1] 30632
    [1]+  Interrupt               sleep 12
    yes
    [1] 30636
    [1]+  Interrupt               sleep 12
    yes
    [1] 30638
    [1]+  Interrupt               sleep 12
    yes
    [1] 30640
    

提交回复
热议问题