等待进程完成的Shell脚本

3

我有一个进程

"verifyEmail"
I run this in script as verifyEmail 0 1000

现在,我该如何在shell脚本中等待这个进程执行完成后再继续下一个指令呢?verifyEmail需要运行超过60分钟。

我尝试了:

while ! checkprocess "verifyEmail"; do   ##Checkprocess is a function which returns 0 or 1
sleep 60                                 ## based on process present or not
done 

2
运行超过60分钟?那是一些强烈的验证。sleep 60只会睡眠60 。另外,为什么它不是同步运行的?你是将其放到后台运行吗? - FatalError
1个回答

2

如果您正常运行进程,则无需进行任何操作。如果您异步运行它,您只需要使用 wait 命令等待即可:

verifyEmail 0 1000
echo This will print after verifyEmail is done!

或者

verifyEmail 0 1000 &
wait $!
echo This will print after verifyEmail is done!

抱歉,但它们都不起作用。我编写了脚本并运行了脚本,稍后使用ps -ef命令进行了检查,仍然发现verifyEmail在后台运行。 - JumpOffBox
你的 verifyEmail 脚本正在以守护进程方式运行。它可能提供了一种禁用该功能或编写 pidfile 的机制。 - William Pursell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接