Reputation: 4125
I've curious about how can I kill all Running jobs at first, and then change all Stopped jobs to Running status in Linux. I have googled a lot but I did not found anything. I just reached a command kill $(jobs -ps)
that kills all jobs (whether running or stopped).
This is my jobs
output:
[1] 92231 Running tail -f myfile &
[2] 92232 Stopped tail -f myfile
[3] 92234 Stopped tail -f myfile
[4] 92236 Stopped tail -f myfile
[5] 92237 Running tail -f myfile &
[6] 92238 Stopped tail -f myfile
[7] 92239 Running tail -f myfile &
[8] 92240 Stopped tail -f myfile
[9] 92241 Stopped tail -f myfile
[10] 92243 Stopped tail -f myfile
[11] 92244 Stopped tail -f myfile
[12] 92245 Stopped tail -f myfile
[13] 92246 Stopped tail -f myfile
[14] 92247 Stopped tail -f myfile
[15] 92248 Stopped tail -f myfile
[16] 92249 Stopped tail -f myfile
[17] 92250 Stopped tail -f myfile
[18] 92251 Stopped tail -f myfile
[19] 92252 Stopped tail -f myfile
[20] 92253 Stopped tail -f myfile
[21] 92255 Stopped tail -f myfile
[22] 92256 Stopped tail -f myfile
[23] 92258 Stopped tail -f myfile
[24] 92259 Stopped tail -f myfile
[25] 92260 Stopped tail -f myfile
[26] 92261 Running tail -f myfile &
[27] 92262 Stopped tail -f myfile
[28] 92263 Stopped tail -f myfile
[29] 92264 Stopped tail -f myfile
[30] 92267 Stopped tail -f myfile
[31] 92268 Stopped tail -f myfile
[32] 92269 Stopped tail -f myfile
[33] 92270 Stopped tail -f myfile
[34] 92271 Stopped tail -f myfile
[35]- 92272 Stopped tail -f myfile
[36]+ 92273 Stopped tail -f myfile
At first, I want to kill all Running processes, and then I want to make the other Stopped ones being Running.
How may I reach this output? I've been thinking about for loop but I'm not sure if I can.
Upvotes: 1
Views: 881
Reputation: 14046
First some useful jobs
options from the bash manual:
-p List only the process ID of the job’s process group leader.
-r Display only running jobs.
-s Display only stopped jobs.
So to kill all running jobs we can do:
kill $(jobs -p -r)
And to restart all stopped jobs:
kill -SIGCONT $(jobs -p -s)
Upvotes: 1