在另一个(已经运行)完成后启动脚本 [英] 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?
一种选择是使用 pgrep 每 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屋!