Tip: signal+trap+sleep+wait

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload
Author Message
MesMurized
DD-WRT Novice


Joined: 08 Aug 2017
Posts: 40

PostPosted: Wed Jan 26, 2022 20:16    Post subject: Tip: signal+trap+sleep+wait Reply with quote
Consider this snippet:
Code:

trap 'echo "Caught Signal"' SIGHUP SIGINT SIGTERM
while true; do
    ...
    sleep infinity
    ...
    ...Anything here will NEVER run
    ...  unless sleep is killed
    ...
done

Why? signals do not interrupt sleep.
Code:

trap 'echo "Caught Signal"' SIGHUP SIGINT SIGTERM
while true; do
    ...
    sleep [ 1 | 60 | xx | infinity ] &
    wait $!
    ...
    ... runs as expected after sleep or signal
    ...
done

Note: sleep process is not terminated

_________________
Current: NetgearR9000 r48865
Retired: Linksys WRT32X r39296, TP-Link Archer C7 v2, LinkSys WRT54G v5
Sponsor
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum