击:对超时/文件溢出而终止执行命令 [英] Bash: Terminate on Timeout/File Overflow while Executing Command

查看:109
本文介绍了击:对超时/文件溢出而终止执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写在bash一个模拟分级脚本。它应该执行一个C程序,这将给一些输出(我重定向到一个文件中。)我想(1)做出了一定时间后,超时还(2)终止如果输出文件达到某个文件大小限制。不知道如何去其中任一。任何帮助吗?谢谢你。

I'm writing a mock-grading script in bash. It's supposed to execute a C program which will give some output (which I redirect to a file.) I'm trying to (1) make it timeout after a certain duration and also (2) terminate if the output file reaches a certain file size limit. Not sure how to go about either of these. Any help? Thanks.

推荐答案

有一个GNU coreutil命令暂停做超时。

There's a GNU coreutil command timeout to do timeouts.

调查的ulimit -f 32 来的最大文件大小设置(以16昆明植物研究所,它计算在512字节块)。

Investigate ulimit -f 32 to set the maximum file size (to 16 KiB; it counts in 512 byte blocks).

异议:

的ulimit是[的的合适,因为我必须创建其他的文件。我需要限制只是其中之一。

ulimit is [not] suitable because I have to create other files as well. I need to limit only one of them.

计数器:除非程序必须创建一个大的文件和一个小文件,你可以限制只是小文件,你可以使用一个子shell,效果良好:

Counter: Unless the program must create a big file and a little file and you have to limit just the little file, you can use a sub-shell to good effect:

(
ulimit -f 32
timeout 10m -- command arg >file
)

上的文件大小的上限被限制为在副壳的命令(这是由在一对括号的标记)。

The limit on file size is restricted to the commands in the sub-shell (which is marked by the pair of parentheses).

这篇关于击:对超时/文件溢出而终止执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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