nanosleep mystery
- From: chandanlinster <chandanlinster@xxxxxxxxx>
- Date: Thu, 13 Dec 2007 10:36:03 -0800 (PST)
Hi,
I executed the following code on slackware 10.2 (with 2.6.22 kernel)
and ubuntu 7.10 (again with 2.6.22 kernel).
On slackware, the value of "diff" is sometimes 0(zero). On ubuntu it
is consistently above 1(one). Can anybody tell me why this may be
happening??
/***************** Code listing ****************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/times.h>
int main(int argc, char *argv[])
{
clock_t t1, t2, diff;
struct timespec req_time, rem_time;
req_time.tv_sec = 0;
req_time.tv_nsec = atol(argv[1]);
do {
if ((t1 = times(NULL)) == (clock_t)(-1)) {
perror("times");
exit(1);
}
if (nanosleep(&req_time, &rem_time) == -1) {
perror("nanosleep");
exit(1);
}
if ((t2 = times(NULL)) == (clock_t)(-1)) {
perror("times");
exit(1);
}
diff = t2 - t1;
printf("diff = %ld\n", diff);
} while (1);
return 0;
}
.
- Follow-Ups:
- Re: nanosleep mystery
- From: Rainer Weikusat
- Re: nanosleep mystery
- From: David Schwartz
- Re: nanosleep mystery
- Prev by Date: Re: process/thread & processor
- Next by Date: Re: automake question
- Previous by thread: read() and EOF
- Next by thread: Re: nanosleep mystery
- Index(es):
Relevant Pages
|