【发布时间】:2013-11-06 22:46:04
【问题描述】:
我尝试在 ksh 脚本中限制允许的子进程。我尝试使用 ulimit(硬值或软值),但子进程总是打破限制(如果花费的时间超过允许的时间)。
# value for a test
Sc_Timeout=2
Sc_FileOutRun=MyScript.log.Running
Sc_Cmd=./AScriptToRunInSubShell.sh
(
ulimit -Ht ${Sc_Timeout}
ulimit -St ${Sc_Timeout}
time (
${Sc_Cmd} >> ${Sc_FileOutRun} 2>&1
) >> ${Sc_FileOutRun} 2>&1
# some other command not relevant for this
)
结果:
1> ./MyScript.log.Running
ulimit -Ht 2
ulimit -St 2
1>> ./MyScript.log.Running 2>& 1
real 0m11.45s
user 0m3.33s
sys 0m4.12s
我预计系统或用户时间会出现超时错误,例如 0m2.00s
当我直接从命令行进行测试时,ulimit Hard 似乎有效地限制了时间但不在脚本中
test/dev 系统是 AIX 6.1,但也应该可以在其他版本以及 sun 和 linux 上运行
【问题讨论】: