如何杀死所有 运行 个作业,然后使停止的作业成为 运行?

How to kill all Running jobs and then make Stopped jobs being Running?

我很好奇如何首先杀死所有 运行 个作业,然后在 Linux 中将所有停止的作业更改为 运行 状态。我用谷歌搜索了很多,但没有找到任何东西。我刚刚收到一个命令 kill $(jobs -ps),它会终止所有作业(无论是 运行 还是已停止)。 这是我的 jobs 输出:

[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

起初,我想杀死所有 运行 个进程,然后我想让其他停止的进程成为 运行。

我怎样才能达到这个输出?我一直在考虑 for 循环,但我不确定我是否可以。

首先是 bash manual 中一些有用的 jobs 选项:

-p List only the process ID of the job’s process group leader.

-r Display only running jobs.

-s Display only stopped jobs.

所以要杀死所有 运行 个工作,我们可以做:

kill $(jobs -p -r)

并重新启动所有已停止的作业:

kill -SIGCONT $(jobs -p -s)