Re: [Bug #12911] Limiting cpu time doesn't work

From: Peter Lojkin
Date: Sun Mar 22 2009 - 01:36:23 EST


Hello,

additional info on subject.
problem first apeared in 2.6.27-git9 and RLIMIT_CPU actually works on process that sets limit but not on its children. examples:

test1.c
#include <sys/time.h>
#include <sys/resource.h>

int main() {
struct rlimit a;
a.rlim_cur=3;
a.rlim_max=5;
setrlimit(RLIMIT_CPU, &a);
while(1);
return 0;
}

test1 dies with "CPU time limit exceeded" after 3sec as expected, but

test2.c
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main() {
struct rlimit a;
int status;

a.rlim_cur=3;
a.rlim_max=5;
setrlimit(RLIMIT_CPU, &a);
if (0==fork())
while(1);
else
wait(&status);
return 0;
}

test2 not get killed. checking limits on child process show that limits set correctly.

two equivalent examples for shell:
sh -c "ulimit -t 3; while true; do true; done"
sh -c "ulimit -t 3; sh -c 'while true; do true; done'"

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/