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