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