2 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .TH clock_getcpuclockid 3 (date) "Linux man-pages (unreleased)"
9 clock_getcpuclockid \- obtain ID of a process CPU-time clock
12 .RI ( libc ", " \-lc ),
17 .RI ( librt ", " \-lrt )
22 .BI "int clock_getcpuclockid(pid_t " pid ", clockid_t *" clockid );
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
31 .BR clock_getcpuclockid ():
33 _POSIX_C_SOURCE >= 200112L
37 .BR clock_getcpuclockid ()
38 function obtains the ID of the CPU-time clock of the process whose ID is
40 and returns it in the location pointed to by
44 is zero, then the clock ID of the CPU-time clock
45 of the calling process is returned.
48 .BR clock_getcpuclockid ()
50 on error, it returns one of the positive error numbers listed in ERRORS.
54 The kernel does not support obtaining the per-process
55 CPU-time clock of another process, and
57 does not specify the calling process.
60 The caller does not have permission to access
61 the CPU-time clock of the process specified by
63 (Specified in POSIX.1-2001;
64 does not occur on Linux unless the kernel does not support
65 obtaining the per-process CPU-time clock of another process.)
68 There is no process with the ID
71 For an explanation of the terms used in this section, see
77 Interface Attribute Value
81 .BR clock_getcpuclockid ()
82 T} Thread safety MT-Safe
93 with the clock ID obtained by a call to
94 .BR clock_getcpuclockid ()
98 is the same as using the clock ID
99 .BR CLOCK_PROCESS_CPUTIME_ID .
101 The example program below obtains the
102 CPU-time clock ID of the process whose ID is given on the command line,
104 .BR clock_gettime (2)
105 to obtain the time on that clock.
106 An example run is the following:
110 .RB "$" " ./a.out 1" " # Show CPU clock of init process"
111 CPU\-time clock for PID 1 is 2.213466748 seconds
116 .\" SRC BEGIN (clock_getcpuclockid.c)
118 #define _XOPEN_SOURCE 600
126 main(int argc, char *argv[])
132 fprintf(stderr, "%s <process\-ID>\en", argv[0]);
136 if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
137 perror("clock_getcpuclockid");
141 if (clock_gettime(clockid, &ts) == \-1) {
142 perror("clock_gettime");
146 printf("CPU\-time clock for PID %s is %jd.%09ld seconds\en",
147 argv[1], (intmax_t) ts.tv_sec, ts.tv_nsec);
153 .BR clock_getres (2),
154 .BR timer_create (2),
155 .BR pthread_getcpuclockid (3),