The explanation of struct timeval in LINUX __linux

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.