linux - 如何制作与进程分离然后重新附加到它的bash脚本?
问题描述
我需要编写一个 bash 脚本来启动一个阻塞进程,然后从中分离,这样我就可以运行一些其他命令来配置这个正在运行的进程,然后重新附加到原始进程,这样 ctrl+c 就会杀死它。
具体来说,这恰好是 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.
解决方案
感谢@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
推荐阅读
- android - ARCore – Anchors 附加到 Trackable 时的作用是什么?
- c# - 引用资源文件的方法的 NUnit 测试用例
- c# - MVC 2.0 中列表的绑定列表
- laravel - 模型关系的推荐 Laravel 路由结构
- node.js - 纽约市不显示数组中函数的覆盖率
- amazon-cloudwatch - 获取 JSON 日志文件中的数组项计数
- eclipse-rcp - Perspectiveswitcher 不会创建命令对象来切换视角
- imagemagick - 调整大小时如何保持图像纵横比?
- xamarin - FlexLayout 内 StackLayout 内的项目在 Xamarin Forms 中未垂直居中
- java - 这段代码有什么问题,它在必须时不会停止