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