ubuntu下的ulimit -t [英] ulimit -t under ubuntu

查看:54
本文介绍了ubuntu下的ulimit -t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running Ubuntu Linux (2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux) and it seems that the command "ulimit -t" does not work properly. I ran:

ulimit -t 1;我的程序

ulimit -t 1; myprogram

其中"myprogram"是一个无限循环.我希望程序在1秒钟后被中断,但并没有停止.我在Linux Fedora安装上尝试了相同的操作,并且按预期工作.

where 'myprogram' is an endless loop. I expected the program to be interrupted after 1 second, but it did not stop. I tried the same thing on a Linux Fedora installation and it worked as expected.

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

Is there some configuration that has to be set for it to work properly?

-tsf

推荐答案

正如 Tsf 所指出的,该问题是由于到内核2.6.28中的错误. 我保留了最初的答案,因为我认为仍然可以提供帮助.

As Tsf pointed out, the problem is due to a bug in kernel 2.6.28. I leave my original answer, because I think it could be helpful anyway.

来自ulimit联机帮助页

From the ulimit manpage

-t The maximum amount of cpu time in seconds.

关于ulimit的计算仅是 CPU时间. 尝试像这样启动程序:

What counts in respect to ulimit is only CPU time. Try to start your program like this:

time myprogram

这将向您显示它实际使用了多少CPU时间.

That will show you how much CPU time it really uses.

我怀疑您的无尽循环包含sleep() 并且睡眠时间不会增加该进程的CPU时间.

My suspicion is that your endless loop contains sleep() and sleep time does not contribute to the CPU time of the process.

一秒钟后被杀死:

me@host:~$ bash
me@host:~$ ulimit -t 1; for (( i=1; 1; i++ )); do a=1; done
Killed

这似乎永远存在(当然不会):

This seems to run forever (but of course does not):

me@host:~$ bash
me@host:~$ ulimit -t 1; for (( i=1; 1; i++ )); do sleep 1; done

像这样测量CPU时间...

Measure CPU time like this...

me@host:~$  time for (( i=1; i<5; i++ )); do sleep 1; done

...以及5秒后...

...and 5 seconds later...

real        0m4.008s
user        0m0.000s
sys         0m0.012s

...仅使用12毫秒CPU时间.

...only 12 ms CPU time used.

我在ubuntu Jaunty Jackalope(9.04)上尝试过

I tried it on 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

这篇关于ubuntu下的ulimit -t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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