对于以下代码,getrusage 在ru_utime.tv_usec
和中返回零ru_utime.tv_sec
。
代码:
#include "stdlib.h"
#include "stdio.h"
#include "sys/time.h"
#include "sys/resource.h"
int getr_return, who = RUSAGE_SELF;
struct rusage usage;
main()
{
getr_return = getrusage(who, &usage);
printf(" getr_return = %d\n", getr_return);
printf(" time taken in seconds = %.61f\n", usage.ru_utime.tv_sec);
printf(" time taken in seconds = %.61f\n", usage.ru_utime.tv_usec);
Some_Mips_consuming_code().
getr_return = getrusage(who, &usage);
printf(" getr_return = %d\n", getr_return);
printf(" time taken in seconds = %.61f\n", usage.ru_utime.tv_sec);
printf(" time taken in seconds = %.61f\n", usage.ru_utime.tv_usec);
exit;
}
输出:
getr_return = 0
time taken in seconds = 0.0000000000000000000000000000000000000000000000000000000000000
time taken in seconds = 0.0000000000000000000000000000000000000000000000000000000000000
getr_return = 0
time taken in seconds = 0.0000000000000000000000000000000000000000000000000000000000000
time taken in seconds = 0.0000000000000000000000000000000000000000000000000000000000000
编译后的代码Linux version 2.6.18-308
在 ARM 板上运行可执行文件Linux version 3.8.1-2.0