clock_getcpuclockid(3) Library Functions Manual clock_getcpuclockid(3) clock_getcpuclockid - ID LIBRARY Standard C library (libc, -lc), since glibc 2.17 Before glibc 2.17, Real-time library (librt, -lrt) #include int clock_getcpuclockid(pid_t pid, clockid_t *clockid); glibc (. feature_test_macros(7)): clock_getcpuclockid(): _POSIX_C_SOURCE >= 200112L The clock_getcpuclockid() function obtains the ID of the CPU-time clock of the process whose ID is pid, and returns it in the location pointed to by clockid. If pid is zero, then the clock ID of the CPU-time clock of the calling process is returned. clock_getcpuclockid() 0; , . ENOSYS pid . EPERM , pid ( POSIX.1-2001; Linux, , ). ESRCH pid . attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |clock_getcpuclockid() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ POSIX.1-2008. glibc 2.2. POSIX.1-2001. clock_gettime(2) ID , clock_getcpuclockid() pid 0, , ID , CLOCK_PROCESS_CPUTIME_ID. ID , ID , clock_gettime(2) . : $ ./a.out 1 # init PID 1 2.213466748 #define _XOPEN_SOURCE 600 #include #include #include #include #include int main(int argc, char *argv[]) { clockid_t clockid; struct timespec ts; if (argc != 2) { fprintf(stderr, "%s \n", argv[0]); exit(EXIT_FAILURE); } if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) { perror("clock_getcpuclockid"); exit(EXIT_FAILURE); } if (clock_gettime(clockid, &ts) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); } printf("CPU-time clock for PID %s is %jd.%09ld seconds\n", argv[1], (intmax_t) ts.tv_sec, ts.tv_nsec); exit(EXIT_SUCCESS); } . clock_getres(2), timer_create(2), pthread_getcpuclockid(3), time(7) Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , Katrin Kutepova , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . clock_getcpuclockid(3)