hi,
if have some program for benchmarking and therefore i
limit time and memory resources from the shell (sh) using
ulimit (under Debian GNU/Linux).
i've also included some code, to give some message on
STDOUT when time limit is exceeded:
void
ntrTimeExit(
int timeSignal )
{
struct rlimit *tLimit = malloc( sizeof( struct rlimit ) );
getrlimit( RLIMIT_CPU, tLimit );
printf( "time limit %9dsec exceeded\n", (int)tLimit->rlim_cur );
free( tLimit );
exit( 1 );
to activate ntrTimeExit() i use the following function:Quote:}
ntrTimeLimit()
{
struct rlimit *tLimit = malloc( sizeof( struct rlimit ) );
getrlimit( RLIMIT_CPU, tLimit );
signal( SIGALRM, ntrTimeExit );
alarm( tLimit->rlim_cur );
free( tLimit );
ntrTimeLimit() is called at the very beginning of main().Quote:}
now i've observed the following "mismatch" of the /usr/bin/time
command (the cpu-time limit was set to 10 minutes (ulimit -t 600)):
when i do NOT call ntrTimeLimit() on one benchmark i got the /usr/bin/time
result:
real 3641.73, user 333.16, system 268.15, user+system 601.31
that is, a real time of more than 1 hour and (user+system) time that matches
the given cpu-time limit.
when I call ntrTimeLimit() on this benchmark i got the result:
real 600.32, user 99.01, system 82.92, user+system 181.93
that is, a real time that matches the given cpu-time limit and a
(user+system) time that is far less from the cpu-time limit.
by the way, in both cases the program aborts on this benchmark.
if your question is now about the size of the process and the percentage,
than this is a good question: In both cases, the CPU percentages are about 5-10%
(yes, it's a hard problem and memory is full (about 1GB)).
but the problem is the different behaviour when i use ntrTimeLimit() and
alarm(), respectively. i was thinking that i really set the alarm function
according to the cpu-time limit given from the shell, but obviously this
is not the case.
does anyone has an explanation to this?
thanks in advance,
marc