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