一个接一个(运行)结束开始脚本 [英] Start script after another one (already running) finishes
问题描述
所以我有一个进程在运行,它会需要几个小时才能完成。我想,一个完成后自动启动另一个程序的权利。请注意,我不能在第一个加一个调用第二个脚本,既不创建另一个其中顺序同时运行。有什么办法在Linux下做到这一点?
So I have a process running, and it will take several hours to complete. I would like to start another process right after that one finishes, automatically. Notice that I can't add a call to the second script in the first one, neither create another which sequentially runs both. Is there any way to do this in Linux?
编辑:一种选择是使用指派,轮询间隔 X
分钟检查过程结束。如果那样,开始另一个。但是,我不喜欢这种解决方案。
One option is to poll every x
minutes using pgrep and check if the process finished. If it did, start the other one. However, I don't like this solution.
PS:两者都是的bash脚本,如果这能帮助
PS: Both are bash scripts, if that helps.
推荐答案
轮询可能是要走的路,但它并不一定可怕。
Polling is probably the way to go, but it doesn't have to be horrible.
pid=$(ps -opid= -C your_script_name)
while [ -d /proc/$pid ] ; do
sleep 1
done && ./your_other_script
这篇关于一个接一个(运行)结束开始脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!