Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ulimit -t under ubuntu

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; myprogram

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

like image 569
Tsf Avatar asked Jun 10 '09 21:06

Tsf


People also ask

What is Ulimit in Ubuntu?

ulimit is a built-in Linux shell command that allows viewing or limiting system resource amounts that individual users consume. Limiting resource usage is valuable in environments with multiple users and system performance issues.

How does Ulimit work in Linux?

ulimit is admin access required Linux shell command which is used to see, set, or limit the resource usage of the current user. It is used to return the number of open file descriptors for each process. It is also used to set restrictions on the resources used by a process.


1 Answers

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.

From the ulimit manpage

-t The maximum amount of cpu time in seconds.

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

time myprogram

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

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

This gets killed after one second:

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

Measure CPU time like this...

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

...and 5 seconds later...

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

...only 12 ms CPU time used.

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
like image 95
Ludwig Weinzierl Avatar answered Oct 31 '22 07:10

Ludwig Weinzierl