OILS / spec / stateful / bug-858-wait-trap.sh View on Github | oilshell.org

55 lines, 39 significant
1# If this is on, wait will exit
2#set -o errexit
3
4action() {
5 echo "from signal"
6}
7
8# wait has an exit code according to the signal!
9trap 'action' USR1
10trap 'action' USR2
11
12echo "Run: kill -USR1 $$; date"
13
14# bash/zsh/mksh: wait is interrupted by USR1
15# dash: wait is NOT interrupted!
16
17async_test() {
18 while true; do
19 date
20 sleep 5 &
21 wait $!
22 echo wait=$?
23 done
24}
25
26async_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
36async_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
47sync_test() {
48 while true; do
49 date
50 sleep 5
51 echo 'next'
52 done
53}
54
55"$@"