1 | # If this is on, wait will exit
|
2 | #set -o errexit
|
3 |
|
4 | action() {
|
5 | echo "from signal"
|
6 | }
|
7 |
|
8 | # wait has an exit code according to the signal!
|
9 | trap 'action' USR1
|
10 | trap 'action' USR2
|
11 |
|
12 | echo "Run: kill -USR1 $$; date"
|
13 |
|
14 | # bash/zsh/mksh: wait is interrupted by USR1
|
15 | # dash: wait is NOT interrupted!
|
16 |
|
17 | async_test() {
|
18 | while true; do
|
19 | date
|
20 | sleep 5 &
|
21 | wait $!
|
22 | echo wait=$?
|
23 | done
|
24 | }
|
25 |
|
26 | async_test2() {
|
27 | echo 'with wait -n'
|
28 | while true; do
|
29 | date
|
30 | sleep 5 &
|
31 | wait -n
|
32 | echo wait=$?
|
33 | done
|
34 | }
|
35 |
|
36 | async_test3() {
|
37 | echo 'with wait'
|
38 | while true; do
|
39 | date
|
40 | sleep 5 &
|
41 | wait
|
42 | echo wait=$?
|
43 | done
|
44 | }
|
45 |
|
46 | # bash/dash/zsh/mksh: signal handler run after sleep
|
47 | sync_test() {
|
48 | while true; do
|
49 | date
|
50 | sleep 5
|
51 | echo 'next'
|
52 | done
|
53 | }
|
54 |
|
55 | "$@"
|