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.
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Use JS/jQuery to scroll a div's content that h
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Is there a non-java, cross platform way to launch
- How exactly do Firebase Analytics handle session d
- Reverse four length of letters with sed in unix
you can use
timeout
command egto check file size, you can stat the file, then do
if/else
see also here if you can't use these GNU tools, or here for some other inspirations.
There's a GNU coreutil command
timeout
to do timeouts.Investigate
ulimit -f 32
to set the maximum file size (to 16 KiB; it counts in 512 byte blocks).Objection:
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:
The limit on file size is restricted to the commands in the sub-shell (which is marked by the pair of parentheses).
This starts yourcommand, redirecting output via dd to youroutputfile and putting a limit of 10000000 bytes on it: dd will terminate and SIGPIPE will be sent to yourcommand
This will wait 5 seconds and kill yourcommand if not already terminated: