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