Linux命令的I / O简单超时 [英] simple timeout on I/O for command for linux

查看:579
本文介绍了Linux命令的I / O简单超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先是这个有趣挑战的背景。持续集成构建通常在开发和测试死锁,循环或导致永无止境测试的其他问题时会出现故障。因此,通知构建失败的所有机制都变得无用。

First the background to this intriguing challenge. The continuous integration build can often have failures during development and testing of deadlocks, loops, or other issues that result in a never ending test. So all the mechanisms for notifying that a build has failed become useless.

如果构建日志文件的输出为零以获得更多,解决方案将是构建脚本超时因为构建过程中常常会写出单元测试的名称,因此超过5分钟。所以这是识别它冻结的最好方法。

The solution will be to have the build script timeout if there's zero output to the build log file for more than 5 minutes since the build routinely writes out the names of unit tests as it proceeds. So that's the best way to identify it's "frozen".

好的。现在的细节...

Okay. Now the nitty gritty...

构建服务器使用Hudson运行一个简单的bash脚本,该脚本调用基于Nant和MSBuild的更复杂的构建脚本(所有在Windows上) 。

The build server uses Hudson to run a simple bash script that invokes the more complex build script based on Nant and MSBuild (all on Windows).

到目前为止,网络上的所有解决方案都涉及命令总运行时间的超时。但是在这种情况下,该解决方案失败了,因为测试可能会在前5分钟内挂起或冻结。

So far all solutions around the net involve a timeout on the total run time of the command. But that solution fails in this case because the tests might hang or freeze in the first 5 minutes.

到目前为止我们的想法:

What we've thought of so far:

首先,这是高级bash命令在Hudson中运行完整的测试套件。

First, here's the high level bash command run the full test suite in Hudson.

build.sh clean free test

该命令只是将所有Nant和MSBuild构建日志记录发送到stdout。

That command simply sends all the Nant and MSBuild build logging to stdout.

很明显,我们需要将输出发送到文件:

It's obvious that we need to tee that output to a file:

build.sh clean free test 2>&1 | tee build.out

然后并行命令需要休眠,检查文件的修改时间和如果超过5分钟杀死主要进程。一个 kill -9 在这一点上没问题 - 一旦冻结就没有任何优雅。

Then in parallel a command needs to sleep, check the modify time of the file and if more than 5 minutes kill the main process. A kill -9 will be fine at that point--nothing graceful needed once it has frozen.

这就是你可以帮忙的部分。

That's the part you can help with.

事实上,我在15年前创建了一个这样的脚本,在一段时间不活动之后,用一条数据电话线连接到日本。我不记得我是怎么做到的。

In fact, I made a script like this over 15 years ago to kill the connection with a data phone line to japan after periods of inactivity but can't remember how I did it.

真诚的,
Wayne

Sincerely, Wayne

推荐答案

build.sh clean free test 2>&1 | tee build.out &
sleep 300
kill -KILL %1

这篇关于Linux命令的I / O简单超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆