如何使bash脚本脱离进程,然后在以后重新附加到该脚本? [英] How to make bash script that detaches from process and then reattached to it later?

查看:66
本文介绍了如何使bash脚本脱离进程,然后在以后重新附加到该脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个bash脚本来启动一个阻塞过程,然后从中分离出来,以便我可以运行一些其他命令来配置该正在运行的过程,然后重新附加到原始过程中,以便ctrl + c将其杀死.

I need to write a bash script that starts a blocking process, then detaches from it so I can run some other commands that configure this running process, then reattach to the original process such that ctrl+c will kill it.

具体来说,这恰好是Google Cloud PubSub模拟器,因此bash脚本看起来类似于以下伪代码:

Specifically, this happens to be the Google Cloud PubSub emulator, so the bash script looks something like the following pseudocode:

# TODO: pubsub will block, but I need to detach from it so I can create topics.
gcloud beta emulators pubsub start --host-port=localhost:8086

python publisher.py myapp create topic1
python publisher.py myapp create topic2

# TODO: Now I need to reattach to the pubsub process.

推荐答案

由于上面@Barmar的评论,我在MacOS上有一个可行的解决方案:

Thanks to @Barmar's comments above, I have a working solution on MacOS:

screen -S pub_sub_emulator -dm gcloud beta emulators pubsub start --host-port=localhost:8086

python publisher.py myapp create topic1
python publisher.py myapp create topic2

screen -r pub_sub_emulator

这篇关于如何使bash脚本脱离进程,然后在以后重新附加到该脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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