Precision with "setrlimit"
Robert Spanjaard
spamtrap at arumes.com
Sun May 22 12:03:16 UTC 2011
On Sun, 22 May 2011 19:07:42 +0800, Maybe Lau wrote:
> 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.
Is this an Ubuntu-specific problem?
If not, you might try the Linux C-programming mailing list:
http://vger.kernel.org/vger-lists.html#linux-c-programming
--
Regards, Robert http://www.arumes.com
More information about the ubuntu-users
mailing list