Precision with "setrlimit"
Maybe Lau
dotkrnl at gmail.com
Sun May 22 11:07:42 UTC 2011
Hello everyone, I'm new here. I'm a Chinese high school student. I hope you
can help me.
When I tried to use setrlimit to limit CPU time of a process, I was in
trouble. My code is like this:
int new_limit_process( char *exec , int time )
{
pid_t ret;
ret = fork();
if ( ret == -1 )
perror( "fork" );
if ( !ret )
{
struct rlimit lim;
if ( time != LIM_INF )
{
lim.rlim_max = lim.rlim_cur = time;
if ( setrlimit( RLIMIT_CPU , &lim ) == -1 )
perror( "setrlimit cpu" );
}
if ( execlp( exec , exec , NULL ) == -1 )
perror( "execlp" );
}
return ret;
}
But when I limited a process's CPU time to 10 sec, it was killed after more
than 1 min. I don't know if it's right with my code and if it's right with
the status.
I'm developing a online application that can use in NOIP, a contest like the
ACM-ICPC, for our school. So I need a high precision.
What's the problem with my code? Or what should I do?
I'm using Ubuntu 11.04 with linux kernel 2.6.38-8-generic.
P.S. I'm not good at English. Sorry for my mistakes if there are.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20110522/804615b7/attachment.html>
More information about the ubuntu-users
mailing list