Linux clock_gettime function details

Source: Internet
Author: User

Long sys_clock_gettime (clockid_t which_clock, struct timespec * TP );

Which_clock parameter description

Clock_realtime

Clock_monotonic: Timing starts from the moment when the system is started, and is not affected by changes in the system time.

Clock_process_cputime_id: time spent by the current process to the CPU of the current Code System

Clock_thread_cputime_id: time spent by the current thread to the CPU of the current Code System

// Test9.c

# Include <stdio. h>
# Include <time. h>

Int main ()
{
Struct timespec time1 = {0, 0 };
Clock_gettime (clock_realtime, & time1 );
Printf ("clock_realtime: % d, % d", time1. TV _ sec, time1. TV _ nsec );
Clock_gettime (clock_monotonic, & time1 );
Printf ("clock_monotonic: % d, % d", time1. TV _ sec, time1. TV _ nsec );
Clock_gettime (clock_process_cputime_id, & time1 );
Printf ("clock_process_cputime_id: % d, % d", time1. TV _ sec, time1. TV _ nsec );
Clock_gettime (clock_thread_cputime_id, & time1 );
Printf ("clock_thread_cputime_id: % d, % d", time1. TV _ sec, time1. TV _ nsec );

Printf ("/n % d/N", time (null ));
Sleep (1 );
}

If compilation fails and the library is not added by default, run it with GCC test9.c-LRT.

Test # time./A. Out

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.