正如Tsf指出的那样,问题是由于内核 2.6.28 中的错误造成的。我留下了我原来的答案,因为我认为无论如何它都会有所帮助。
从 ulimit 联机帮助页
-t The maximum amount of cpu time
in seconds.
就 ulimit 而言,重要的是CPU time。尝试像这样启动您的程序:
time myprogram
这将向您显示它实际使用了多少 CPU 时间。
我怀疑你的无限循环包含sleep()
并且睡眠时间不会影响进程的 CPU 时间。
这会在一秒钟后被杀死:
me@host:~$ bash
me@host:~$ ulimit -t 1; for (( i=1; 1; i++ )); do a=1; done
Killed
这似乎永远运行(但当然不会):
me@host:~$ bash
me@host:~$ ulimit -t 1; for (( i=1; 1; i++ )); do sleep 1; done
像这样测量CPU时间......
me@host:~$ time for (( i=1; i<5; i++ )); do sleep 1; done
……5秒后……
real 0m4.008s
user 0m0.000s
sys 0m0.012s
...仅使用了 12 毫秒的 CPU 时间。
我在 ubuntu Jaunty Jackalope (9.04) 上试过
Linux host 2.6.28-11-generic #42-Ubuntu SMP
Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux