簡體   English   中英

如何使bash腳本脫離進程,然后在以后重新附加到該腳本?

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

我需要編寫一個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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM