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