【问题标题】:Script in bash to wait on the process and then give up [duplicate]bash中的脚本等待进程然后放弃[重复]
【发布时间】:2015-06-22 01:03:43
【问题描述】:

我的脚本有时会挂起。

我的目标是等到脚本完成,或者如果它在 30 秒后没有出现并带有一些返回码,则终止它。

(function) & pid=$!
 wait $pid || sleep 30 || kill -9 $pid
 finished=$?

所以我在想上面。如果进程提前结束,我不想浪费额外的第二次睡眠,这就是我使用等待的原因。

这是正确的还是更好的方法?

【问题讨论】:

标签: linux bash shell


【解决方案1】:

有一个更好的方法:使用timeout 命令。

更多详情请见Timeout a command in bash without unnecessary delay

【讨论】:

    猜你喜欢
    • 2018-01-30
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    相关资源
    最近更新 更多