简体   繁体   English

如何使bash脚本脱离进程,然后在以后重新附加到该脚本?

[英]How to make bash script that detaches from process and then reattached to it later?

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

Specifically, this happens to be the Google Cloud PubSub emulator, so the bash script looks something like the following pseudocode: 具体来说,这恰好是Google Cloud PubSub模拟器,因此bash脚本看起来类似于以下伪代码:

# 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.

Thanks to @Barmar's comments above, I have a working solution on MacOS: 感谢上面的@Barmar的评论,我在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM