【问题标题】:How to kill all Running jobs and then make Stopped jobs being Running?如何杀死所有正在运行的作业,然后使已停止的作业正在运行?
【发布时间】:2020-10-31 19:59:32
【问题描述】:

我很好奇如何首先杀死所有正在运行的作业,然后在 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循环,但我不确定我是否可以。

【问题讨论】:

    标签: linux jobs


    【解决方案1】:

    首先来自bash manual的一些有用的jobs选项:

    -p 仅列出作业的进程组负责人的进程 ID。

    -r 仅显示正在运行的作业。

    -s 仅显示已停止的作业。

    所以要杀死我们可以做的所有正在运行的作业:

    kill $(jobs -p -r)
    

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

    kill -SIGCONT $(jobs -p -s)
    

    【讨论】:

    • 感谢@kaylum 的回复。我使用 Ubuntu,并且在 man 和 info 中没有作业命令的条目,所以我在终端中没有找到任何内容。
    猜你喜欢
    • 2013-12-04
    • 2019-11-09
    • 2014-11-11
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    相关资源
    最近更新 更多