source: trunk/essentials/app-shells/bash/tests/jobs.tests

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 3.0 KB
Line 
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
15jobs
16echo $?
17
18# a no-such-job error, since we can use job control notation without job control
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
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
99# someday this may mean to disown all stopped jobs, but for now it is
100# an error
101disown -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
105disown %1
106
107# this, however, is an error
108disown %2
109
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 &
118sleep 350 &
119sleep 400 &
120
121jobs
122
123echo running jobs:
124jobs -r
125
126# should be an error
127kill -n 1 %4
128# should be an error
129jobs %4
130echo current job:
131jobs %+
132echo previous job:
133jobs %-
134
135kill -STOP %2
136sleep 5 # give time for the shell to get the stop notification
137echo after kill -STOP
138echo running jobs:
139jobs -r
140echo stopped jobs:
141jobs -s
142
143disown %1
144
145echo after disown
146jobs
147echo running jobs:
148jobs -r
149echo stopped jobs:
150jobs -s
151
152kill -s CONT %2
153echo after kill -s CONT
154echo running jobs:
155jobs -r
156echo stopped jobs:
157jobs -s
158
159kill -STOP %3
160sleep 5 # give time for the shell to get the stop notification
161echo after kill -STOP, backgrounding %3:
162bg %3
163
164disown -h %2
165
166# make sure the killed processes don't cause a message
167exec 5>&2
168exec 2>/dev/null
169
170echo killing...
171kill -n 9 %2 %3
172wait # make sure we reap the processes while stderr is still redirected
173echo done
174
175exec 2>&5
176
177sleep 10 &
178kill -STOP %1
179sleep 5 # give time for the shell to get the stop notification
180echo after KILL -STOP, foregrounding %1
181fg %1
182
183echo done
Note: See TracBrowser for help on using the repository browser.