bash 脚本超时后终止命令
我有 bash 脚本,适用于循环中的许多文件。它编译,检查结果等。 现在我想在其中一个文件内出现无限循环的情况下进行安全保护。像这样的东西: 如果5分钟后还没有完成。终止该进程并提供有关该进程的信息。
gcc -Wall -o "${FN}_execute" ${FN} 2> ${FN}_c_compilation.txt
./${FN}_execute $PARAM > ${FN}_c_result.txt
怎么做呢?
I have bash script that work for many files in loop. It compiles, check the result etc.
Now I'd like to make a security in case of infinity loop inside of one of thouse files. something like:
If it's not done after 5 min. Kill the process and gave info about that.
gcc -Wall -o "${FN}_execute" ${FN} 2> ${FN}_c_compilation.txt
./${FN}_execute $PARAM > ${FN}_c_result.txt
How to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下:
http://www.bashcookbook.com/ bashinfo/source/bash-4.0/examples/scripts/timeout3
Take a look at:
http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3
您可以记录开始时间(以秒为单位),然后检查当前时间(以秒为单位)是否超过 300。
但是为什么要编写脚本来手动编译文件呢?
make
没有做你想要的吗?You could record the start time (in seconds) and just check if the current time (in seconds) is more than 300.
But why are you writing a script to compile files manually? Doesn't
make
do what you want?