[ TOP | Recently ]

2010-10-16 getrusage


#include <stdio.h>
#include <sys/resource.h>
#include <sys/param.h>

int
main(int argc, char *argv[])
{
	struct rusage r;
	int i;

	for (i = 0; ; i++) {
#if 1
		int j;
		if ((i % 30) == 0) {
			for (j = 0; j < 1000000; j++)
				;
		}
#endif

		getrusage(RUSAGE_SELF, &r);

#ifdef __FreeBSD__
		printf("%8d.%06ld\n", r.ru_stime.tv_sec, r.ru_stime.tv_usec);
#elif defined(__NetBSD__)
#if (__NetBSD_Version__ >= 599000700)
		printf("%8llu.%06d\n", r.ru_stime.tv_sec, r.ru_stime.tv_usec);
#else
		printf("%8ld.%06ld\n", r.ru_stime.tv_sec, r.ru_stime.tv_usec);
#endif
#else
		printf("%8ld.%06ld\n", r.ru_stime.tv_sec, r.ru_stime.tv_usec);
#endif
		fflush(stdout);
	}
	return 0;
}

をNetBSDで実行したら

           :
       0.010464
       0.010465
       0.010465
       0.010465
       0.009998
       0.009998
       0.009999
       0.009999
           :

のように ru_stime が巻き戻ることがある。豪謎。

#if 1 の空ループを入れると起きやすくなるっぽい気がする。
(でも入れなくても起きた)

スケジューラまわり? 忙しいので詳細調査は後日。


EOF