gpt4 book ai didi

linux - ubuntu下的ulimit -t

转载 作者:IT王子 更新时间:2023-10-29 00:10:36 26 4
gpt4 key购买 nike

我正在运行 Ubuntu Linux (2.6.28-11-generic#42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux),似乎命令“ulimit -t”不起作用适本地。我跑了:

ulimit -t 1;我的程序

其中“myprogram”是一个无限循环。我预计程序会在 1 秒后中断,但它并没有停止。我在 Linux Fedora 安装上尝试了同样的事情,它按预期工作。

是否必须设置一些配置才能使其正常工作?

-- tsf

最佳答案

作为Tsf指出,问题是由于 bug in kernel 2.6.28 .我留下我原来的答案,因为我认为它无论如何都会有帮助。

来自 ulimit 手册页

-t The maximum amount of cpu time in seconds.

对于 ulimit 而言,重要的只是 CPU 时间。尝试像这样启动您的程序:

time myprogram

这将显示它实际使用了多少 CPU 时间。

我怀疑你的无限循环包含 sleep() 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

关于linux - ubuntu下的ulimit -t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/978317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com