Implementing infinite wait in shell scripting

前端 未结 7 578
独厮守ぢ
独厮守ぢ 2021-02-05 04:30

This may sound trivial, but I\'m pretty sure this question hasn\'t been asked, or at least I can\'t find it.

I\'m looking for a way to construct an infinite wait

7条回答
  •  执念已碎
    2021-02-05 05:26

    Here's a solution without a loop:

    #!/usr/local/bin/dash
    
    echo $$
    
    # -$$: kill process group (parent and children)
    #trap 'trap - TERM; kill 0' TERM
    #trap 'trap - INT TERM; kill 0' INT TERM
    
    trap 'trap - TERM; kill -s TERM -- -$$' TERM
    
    tail -f /dev/null & wait
    
    exit 0
    

提交回复
热议问题