]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/jobs5.sub
e6ffb44e6a945a3983256596e9e61dac31dc35eb
[thirdparty/bash.git] / tests / jobs5.sub
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 #
14
15 # framework to test new `wait -n' option that waits for any job to finish
16
17 set -m
18
19 sleep 20 &
20 { sleep 2; exit 12; } &
21 sleep 20 &
22
23 wait -n
24 echo $?
25
26 jobs
27 disown -a
28
29 { sleep 1 ; exit 4; } &
30 { sleep 2 ; exit 5; } & bgpid1=$!
31 { sleep 4 ; exit 6; } &
32
33 wait -p wvar -n %2 %3
34 case "$wvar" in
35 $bgpid1) echo $?: ok 1;;
36 *) echo bad 1;;
37 esac
38
39 { sleep 1 ; exit 2; } & bgpid2=$!
40 wait -p wvar -n %8 $!
41 case $wvar in
42 $bgpid2) echo $?: ok 2;;
43 *) echo bad 2;;
44 esac
45
46 disown -a
47
48 { sleep 3; exit 1; } & { sleep 1; exit 2; } & bgpid3=$!
49 { sleep 3; exit 3; } & { sleep 3; exit 4; } &
50
51 wait -n -p wpid %1 %2 %3 %4
52
53 case $wpid in
54 $bgpid3) echo $?: ok 3;;
55 *) echo bad 3 ;;
56 esac
57
58 disown -a
59
60 unset bgpid1 bgpid2 bgpid3
61 unset wpid