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