Precision with "setrlimit"

Maybe Lau dotkrnl at gmail.com
Sun May 22 12:42:59 UTC 2011


Thank you. I'll try. But I don't know how to use mailing list well, how can I post there? It seems that I can't send my post directly.

And am I correct to reply like this?

Thank you for helping me -- a beginner.

在 2011-5-22,20:03,Robert Spanjaard <spamtrap at arumes.com> 写道:

> 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
> 
> 
> -- 
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users




More information about the ubuntu-users mailing list