]>
Commit | Line | Data |
---|---|---|
8868edaf CR |
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 | # | |
cce855bc JA |
14 | # test out %+, jobs -p, and $! agreement in a subshell first |
15 | ${THIS_SH} ./jobs1.sub | |
16 | ||
17 | # test out fg/bg failure in a subshell | |
18 | ${THIS_SH} ./jobs2.sub | |
19 | ||
bb70624e JA |
20 | # test out behavior of waiting for background pids -- bug in versions |
21 | # before 2.03 | |
22 | ${THIS_SH} ./jobs3.sub | |
23 | ||
b80f6443 JA |
24 | # test out behavior of using job control notation when job control is not |
25 | # active | |
26 | ${THIS_SH} ./jobs4.sub | |
27 | ||
ac50fbac CR |
28 | # test out wait -n framework |
29 | ${THIS_SH} ./jobs5.sub | |
30 | ||
d233b485 CR |
31 | # test out wait -f framework |
32 | ${THIS_SH} ./jobs6.sub | |
33 | ||
8868edaf CR |
34 | ${THIS_SH} ./jobs7.sub |
35 | ||
d166f048 JA |
36 | jobs |
37 | echo $? | |
38 | ||
b80f6443 | 39 | # a no-such-job error, since we can use job control notation without job control |
cce855bc JA |
40 | wait %1 |
41 | ||
42 | # make sure we can't fg a job started when job control was not active | |
43 | sleep 30 & | |
44 | pid=$! | |
45 | fg %1 | |
46 | # make sure the killed processes don't cause a message | |
47 | exec 5>&2 | |
48 | exec 2>/dev/null | |
49 | kill -n 9 $pid | |
50 | wait # make sure we reap the processes while stderr is still redirected | |
51 | exec 2>&5 | |
52 | ||
d166f048 | 53 | echo wait-for-pid |
8868edaf | 54 | sleep 4 & |
d166f048 JA |
55 | wait $! |
56 | ||
57 | echo wait-errors | |
58 | wait 1-1 | |
59 | wait -- -4 | |
60 | ||
61 | echo wait-for-background-pids | |
8868edaf CR |
62 | sleep 2 & |
63 | sleep 4 & | |
d166f048 JA |
64 | wait |
65 | ||
66 | echo async list wait-for-background-pids | |
8868edaf | 67 | sleep 2 & sleep 4 & |
d166f048 JA |
68 | wait |
69 | ||
70 | echo async list wait for child | |
8868edaf | 71 | sleep 2 & echo forked |
d166f048 JA |
72 | wait |
73 | ||
74 | echo wait-when-no-children | |
75 | wait | |
76 | ||
8868edaf CR |
77 | echo posix jobs output |
78 | ${THIS_SH} -o posix -c 'sleep 1 & P=$! ; sleep 2; jobs; wait' | |
79 | ||
d166f048 JA |
80 | set -m |
81 | ||
82 | echo wait-for-job | |
8868edaf | 83 | sleep 3 & |
d166f048 JA |
84 | wait %2 # this should be a no-such-job error |
85 | echo $? | |
86 | wait %1 | |
87 | ||
88 | echo async list wait-for-job | |
8868edaf | 89 | sleep 2 & echo forked |
d166f048 JA |
90 | wait %1 |
91 | ||
92 | echo fg-bg 1 | |
8868edaf | 93 | sleep 2 & |
d166f048 JA |
94 | %1 |
95 | ||
96 | echo fg-bg 2 | |
8868edaf | 97 | sleep 2 & |
d166f048 JA |
98 | fg %% |
99 | ||
100 | echo fg-bg 3 | |
8868edaf | 101 | sleep 2 & |
d166f048 JA |
102 | fg %s |
103 | ||
104 | echo fg-bg 4 | |
8868edaf | 105 | sleep 2 & |
d166f048 JA |
106 | fg %?ee |
107 | ||
108 | # these next two are error cases | |
109 | echo fg-bg 5 | |
8868edaf | 110 | sleep 2 & |
d166f048 JA |
111 | fg %2 # this should be a no-such-job error |
112 | bg %1 # this should be a `bg background job?' error | |
113 | wait | |
114 | ||
115 | # these may someday mean to start the jobs, but not print the line | |
116 | # describing the status, but for now they are errors | |
117 | echo fg-bg 6 | |
8868edaf | 118 | sleep 2 & |
d166f048 JA |
119 | fg -s %1 |
120 | bg -s %1 | |
121 | wait | |
122 | ||
cce855bc | 123 | # someday this may mean to disown all stopped jobs, but for now it is |
d166f048 | 124 | # an error |
cce855bc | 125 | disown -s |
d166f048 | 126 | |
cce855bc JA |
127 | # this is an error -- the job with the pid that is the value of $! is |
128 | # retained only until a `wait' is performed | |
d166f048 JA |
129 | disown %1 |
130 | ||
cce855bc JA |
131 | # this, however, is an error |
132 | disown %2 | |
133 | ||
d166f048 JA |
134 | echo wait-for-non-child |
135 | wait 1 | |
136 | echo $? | |
137 | ||
138 | exit 1 | exit 2 | exit 3 | |
139 | echo $? -- ${PIPESTATUS[@]} -- ${PIPESTATUS[0]} - ${PIPESTATUS[1]} - ${PIPESTATUS[2]} | |
140 | ||
141 | sleep 300 & | |
0001803f | 142 | sleep300pid=$! |
d166f048 JA |
143 | sleep 350 & |
144 | sleep 400 & | |
145 | ||
146 | jobs | |
147 | ||
148 | echo running jobs: | |
149 | jobs -r | |
150 | ||
151 | # should be an error | |
152 | kill -n 1 %4 | |
cce855bc JA |
153 | # should be an error |
154 | jobs %4 | |
155 | echo current job: | |
156 | jobs %+ | |
157 | echo previous job: | |
158 | jobs %- | |
d166f048 JA |
159 | |
160 | kill -STOP %2 | |
8868edaf | 161 | sleep 3 # give time for the shell to get the stop notification |
d166f048 JA |
162 | echo after kill -STOP |
163 | echo running jobs: | |
164 | jobs -r | |
165 | echo stopped jobs: | |
166 | jobs -s | |
167 | ||
168 | disown %1 | |
169 | ||
170 | echo after disown | |
171 | jobs | |
172 | echo running jobs: | |
173 | jobs -r | |
174 | echo stopped jobs: | |
175 | jobs -s | |
176 | ||
177 | kill -s CONT %2 | |
178 | echo after kill -s CONT | |
179 | echo running jobs: | |
180 | jobs -r | |
181 | echo stopped jobs: | |
182 | jobs -s | |
183 | ||
184 | kill -STOP %3 | |
8868edaf | 185 | sleep 3 # give time for the shell to get the stop notification |
d166f048 JA |
186 | echo after kill -STOP, backgrounding %3: |
187 | bg %3 | |
188 | ||
189 | disown -h %2 | |
190 | ||
191 | # make sure the killed processes don't cause a message | |
192 | exec 5>&2 | |
193 | exec 2>/dev/null | |
194 | ||
195 | echo killing... | |
0001803f | 196 | kill -n 9 $sleep300pid |
d166f048 JA |
197 | kill -n 9 %2 %3 |
198 | wait # make sure we reap the processes while stderr is still redirected | |
199 | echo done | |
200 | ||
201 | exec 2>&5 | |
202 | ||
8868edaf | 203 | sleep 4 & |
d166f048 | 204 | kill -STOP %1 |
8868edaf | 205 | sleep 2 # give time for the shell to get the stop notification |
d166f048 JA |
206 | echo after KILL -STOP, foregrounding %1 |
207 | fg %1 | |
208 | ||
209 | echo done |