在 Bash 中给定超时后如何杀死子进程? - How to kill a child process after a given timeout in Bash?

问题:

I have a bash script that launches a child process that crashes (actually, hangs) from time to time and with no apparent reason (closed source, so there isn't much I can do about it).我有一个 bash 脚本,它启动一个子进程,该进程不时崩溃(实际上,挂起)并且没有明显的原因(封闭源代码,所以我无能为力)。 As a result, I would like to be able to launch this process for a given amount of time, and kill it if it did not return successfully after a given amount of time.因此,我希望能够在给定的时间内启动此进程,如果在给定的时间后没有成功返回,则将其终止。

Is there a simple and robust way to achieve that using bash?有没有一种简单强大的方法可以使用 bash 来实现这一目标?

PS: tell me if this question is better suited to serverfault or superuser. PS:告诉我这个问题是否更适合 serverfault 或超级用户。


解决方案:

参考一: https://en.stackoom.com/question/Lef3
参考二: https://stackoom.com/question/Lef3
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章