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