1# This program is free software: you can redistribute it and/or modify 2# it under the terms of the GNU General Public License as published by 3# the Free Software Foundation, either version 3 of the License, or 4# (at your option) any later version. 5# 6# This program is distributed in the hope that it will be useful, 7# but WITHOUT ANY WARRANTY; without even the implied warranty of 8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9# GNU General Public License for more details. 10# 11# You should have received a copy of the GNU General Public License 12# along with this program. If not, see <http://www.gnu.org/licenses/>. 13# 14# test out %+, jobs -p, and $! agreement in a subshell first 15${THIS_SH} ./jobs1.sub 16 17# test out fg/bg failure in a subshell 18${THIS_SH} ./jobs2.sub 19 20# test out behavior of waiting for background pids -- bug in versions 21# before 2.03 22${THIS_SH} ./jobs3.sub 23 24# test out behavior of using job control notation when job control is not 25# active 26${THIS_SH} ./jobs4.sub 27 28# test out wait -n framework 29${THIS_SH} ./jobs5.sub 30 31# test out wait -f framework 32${THIS_SH} ./jobs6.sub 33 34${THIS_SH} ./jobs7.sub 35 36jobs 37echo $? 38 39# a no-such-job error, since we can use job control notation without job control 40wait %1 41 42# make sure we can't fg a job started when job control was not active 43sleep 30 & 44pid=$! 45fg %1 46# make sure the killed processes don't cause a message 47exec 5>&2 48exec 2>/dev/null 49kill -n 9 $pid 50wait # make sure we reap the processes while stderr is still redirected 51exec 2>&5 52 53echo wait-for-pid 54sleep 4 & 55wait $! 56 57echo wait-errors 58wait 1-1 59wait -- -4 60 61echo wait-for-background-pids 62sleep 2 & 63sleep 4 & 64wait 65 66echo async list wait-for-background-pids 67sleep 2 & sleep 4 & 68wait 69 70echo async list wait for child 71sleep 2 & echo forked 72wait 73 74echo wait-when-no-children 75wait 76 77echo posix jobs output 78${THIS_SH} -o posix -c 'sleep 1 & P=$! ; sleep 2; jobs; wait' 79 80set -m 81 82echo wait-for-job 83sleep 3 & 84wait %2 # this should be a no-such-job error 85echo $? 86wait %1 87 88echo async list wait-for-job 89sleep 2 & echo forked 90wait %1 91 92echo fg-bg 1 93sleep 2 & 94%1 95 96echo fg-bg 2 97sleep 2 & 98fg %% 99 100echo fg-bg 3 101sleep 2 & 102fg %s 103 104echo fg-bg 4 105sleep 2 & 106fg %?ee 107 108# these next two are error cases 109echo fg-bg 5 110sleep 2 & 111fg %2 # this should be a no-such-job error 112bg %1 # this should be a `bg background job?' error 113wait 114 115# these may someday mean to start the jobs, but not print the line 116# describing the status, but for now they are errors 117echo fg-bg 6 118sleep 2 & 119fg -s %1 120bg -s %1 121wait 122 123# someday this may mean to disown all stopped jobs, but for now it is 124# an error 125disown -s 126 127# this is an error -- the job with the pid that is the value of $! is 128# retained only until a `wait' is performed 129disown %1 130 131# this, however, is an error 132disown %2 133 134echo wait-for-non-child 135wait 1 136echo $? 137 138exit 1 | exit 2 | exit 3 139echo $? -- ${PIPESTATUS[@]} -- ${PIPESTATUS[0]} - ${PIPESTATUS[1]} - ${PIPESTATUS[2]} 140 141sleep 300 & 142sleep300pid=$! 143sleep 350 & 144sleep 400 & 145 146jobs 147 148echo running jobs: 149jobs -r 150 151# should be an error 152kill -n 1 %4 153# should be an error 154jobs %4 155echo current job: 156jobs %+ 157echo previous job: 158jobs %- 159 160kill -STOP %2 161sleep 3 # give time for the shell to get the stop notification 162echo after kill -STOP 163echo running jobs: 164jobs -r 165echo stopped jobs: 166jobs -s 167 168disown %1 169 170echo after disown 171jobs 172echo running jobs: 173jobs -r 174echo stopped jobs: 175jobs -s 176 177kill -s CONT %2 178echo after kill -s CONT 179echo running jobs: 180jobs -r 181echo stopped jobs: 182jobs -s 183 184kill -STOP %3 185sleep 3 # give time for the shell to get the stop notification 186echo after kill -STOP, backgrounding %3: 187bg %3 188 189disown -h %2 190 191# make sure the killed processes don't cause a message 192exec 5>&2 193exec 2>/dev/null 194 195echo killing... 196kill -n 9 $sleep300pid 197kill -n 9 %2 %3 198wait # make sure we reap the processes while stderr is still redirected 199echo done 200 201exec 2>&5 202 203sleep 4 & 204kill -STOP %1 205sleep 2 # give time for the shell to get the stop notification 206echo after KILL -STOP, foregrounding %1 207fg %1 208 209echo done 210