Imported from ../bash-3.0.tar.gz.
[platform/upstream/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 # test out behavior of waiting for background pids -- bug in versions
8 # before 2.03
9 ${THIS_SH} ./jobs3.sub
10
11 # test out behavior of using job control notation when job control is not
12 # active
13 ${THIS_SH} ./jobs4.sub
14
15 jobs
16 echo $?
17
18 # a no-such-job error, since we can use job control notation without job control
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
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
99 # someday this may mean to disown all stopped jobs, but for now it is
100 # an error
101 disown -s
102
103 # this is an error -- the job with the pid that is the value of $! is
104 # retained only until a `wait' is performed
105 disown %1
106
107 # this, however, is an error
108 disown %2
109
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 &
118 sleep 350 &
119 sleep 400 &
120
121 jobs
122
123 echo running jobs:
124 jobs -r
125
126 # should be an error
127 kill -n 1 %4
128 # should be an error
129 jobs %4
130 echo current job:
131 jobs %+
132 echo previous job:
133 jobs %-
134
135 kill -STOP %2
136 sleep 5 # give time for the shell to get the stop notification
137 echo after kill -STOP
138 echo running jobs:
139 jobs -r
140 echo stopped jobs:
141 jobs -s
142
143 disown %1
144
145 echo after disown
146 jobs
147 echo running jobs:
148 jobs -r
149 echo stopped jobs:
150 jobs -s
151
152 kill -s CONT %2
153 echo after kill -s CONT
154 echo running jobs:
155 jobs -r
156 echo stopped jobs:
157 jobs -s
158
159 kill -STOP %3
160 sleep 5 # give time for the shell to get the stop notification
161 echo after kill -STOP, backgrounding %3:
162 bg %3
163
164 disown -h %2
165
166 # make sure the killed processes don't cause a message
167 exec 5>&2
168 exec 2>/dev/null
169
170 echo killing...
171 kill -n 9 %2 %3
172 wait    # make sure we reap the processes while stderr is still redirected
173 echo done
174
175 exec 2>&5
176
177 sleep 10 &
178 kill -STOP %1
179 sleep 5 # give time for the shell to get the stop notification
180 echo after KILL -STOP, foregrounding %1
181 fg %1
182
183 echo done