BASH脚本暂停/继续执行脚本中的进程 [英] BASH script suspend/continue a process within script

查看:87
本文介绍了BASH脚本暂停/继续执行脚本中的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在编写的bash脚本中,我试图在后台启动一个进程(睡眠),然后将其挂起.最后,该过程完成.出于某种原因,当我发送带有停止信号的kill命令时,它一直保持运行状态,好像什么也没收到一样.我可以从命令行执行此操作,但是bash脚本无法按预期运行.

In my bash script I am writing, I am trying to start a process (sleep) in the background and then suspend it. Finally, the process with be finished. For some reason through, when I send the kill command with the stop signal, it just keeps running as if it received nothing. I can do this from the command line, but the bash script is not working as intended.

sleep 15&
pid=$!
kill -s STOP $pid
jobs
kill -s CONT $pid

推荐答案

您可以通过在脚本中启用监视模式"来使其工作: set -m

You can make it work by enabling 'monitor mode' in your script: set -m

请参见> why-cant-i-use-bash脚本中的工作控制以获取更多信息

这篇关于BASH脚本暂停/继续执行脚本中的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆