Turn from: http://nathanxu.blog.51cto.com/50836/56663
The questions are as follows:
In the description of the Gettimeofday function in the man page of Debian Linux, there is a description:
DESCRIPTION
The functions Gettimeofdayand Settimeofday can get and set the time as
As a timezone. The tvargument is a timeval struct, as specified
In<sys/time.h>:
struct Timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
The description of tv_usec is the millisecond portion of the time. In practice, the function and the Timeval returned by the Linux kernel
The time value of the type, tv_usec represents the Microsecond precision (10-6-second square seconds).
The test code is as follows:
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int Gettimeofday (structtimeval *tv, struct timezone *tz);
int main (int argc,char * argv[]) {
struct Timeval TV;
while (1) {
Gettimeofday (&tv,null);
printf ("time%u:%u\n", tv.tv_sec,tv.tv_usec);
Sleep (2);
}
return 0;
}
The result returned is:
evil@dcenter:~/tmp$./a.out
Time 1,142,077,839:903,605
Time 1,142,077,841:910,129
Time 1,142,077,843:920,155
Time 1,142,077,845:930,180
Time 1,142,077,847:940,205
Time 1,142,077,849:950,231
Time 1,142,077,851:960,256
Time 1,142,077,853:970,280
Time 1,142,077,855:980,307
Time 1,142,077,857:990,331