Denis Vlasenko | 81887e2 | 2008-02-13 18:09:56 +0000 | [diff] [blame] | 1 | trap "echo got signal" USR1 |
2 | |||||
3 | for try in 1 2 3 4 5; do | ||||
4 | kill -USR1 $$ | ||||
Denis Vlasenko | 5c13270 | 2008-07-26 13:53:42 +0000 | [diff] [blame] | 5 | sleep 0.2 |
6 | echo "sent $try signal" | ||||
Denis Vlasenko | 81887e2 | 2008-02-13 18:09:56 +0000 | [diff] [blame] | 7 | done & |
8 | |||||
Denys Vlasenko | e3c6e19 | 2009-10-09 23:35:30 +0200 | [diff] [blame^] | 9 | # Ensure "wait" has something to wait for |
Denis Vlasenko | 5c13270 | 2008-07-26 13:53:42 +0000 | [diff] [blame] | 10 | sleep 2 & |
Denis Vlasenko | 81887e2 | 2008-02-13 18:09:56 +0000 | [diff] [blame] | 11 | |
Denys Vlasenko | 3dc4a3e | 2009-10-09 23:08:28 +0200 | [diff] [blame] | 12 | # Ensure we do not execute "trap" below before "kill -USR1" above |
13 | # (was getting failure on loaded machine without this) | ||||
14 | sleep 0.1 | ||||
15 | |||||
Denis Vlasenko | 5c13270 | 2008-07-26 13:53:42 +0000 | [diff] [blame] | 16 | sleeping=true |
Denis Vlasenko | 81887e2 | 2008-02-13 18:09:56 +0000 | [diff] [blame] | 17 | while $sleeping; do |
18 | trap | ||||
19 | if wait %%; then | ||||
Denis Vlasenko | 5c13270 | 2008-07-26 13:53:42 +0000 | [diff] [blame] | 20 | echo "sleep completed" |
Denis Vlasenko | 81887e2 | 2008-02-13 18:09:56 +0000 | [diff] [blame] | 21 | sleeping=false |
22 | elif [ $? == 127 ]; then | ||||
Denis Vlasenko | 5c13270 | 2008-07-26 13:53:42 +0000 | [diff] [blame] | 23 | echo "BUG: no processes to wait for?!" |
Denis Vlasenko | 81887e2 | 2008-02-13 18:09:56 +0000 | [diff] [blame] | 24 | sleeping=false |
25 | else | ||||
Denis Vlasenko | 5c13270 | 2008-07-26 13:53:42 +0000 | [diff] [blame] | 26 | echo "wait interrupted" |
Denis Vlasenko | 81887e2 | 2008-02-13 18:09:56 +0000 | [diff] [blame] | 27 | fi |
28 | done |