1 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH CLOCK_GETCPUCLOCKID 3 2017-09-15 "Linux" "Linux Programmer's Manual"
28 clock_getcpuclockid \- obtain ID of a process CPU-time clock
33 .BI "int clock_getcpuclockid(pid_t " pid ", clockid_t *" clock_id );
36 Link with \fI\-lrt\fP (only for glibc versions before 2.17).
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
44 .BR clock_getcpuclockid ():
46 _POSIX_C_SOURCE\ >=\ 200112L
51 .BR clock_getcpuclockid ()
52 function obtains the ID of the CPU-time clock of the process whose ID is
54 and returns it in the location pointed to by
58 is zero, then the clock ID of the CPU-time clock
59 of the calling process is returned.
62 .BR clock_getcpuclockid ()
64 on error, it returns one of the positive error numbers listed in ERRORS.
68 The kernel does not support obtaining the per-process
69 CPU-time clock of another process, and
71 does not specify the calling process.
74 The caller does not have permission to access
75 the CPU-time clock of the process specified by
77 (Specified in POSIX.1-2001;
78 does not occur on Linux unless the kernel does not support
79 obtaining the per-process CPU-time clock of another process.)
82 There is no process with the ID
86 .BR clock_getcpuclockid ()
87 function is available in glibc since version 2.2.
89 For an explanation of the terms used in this section, see
95 Interface Attribute Value
97 .BR clock_getcpuclockid ()
98 T} Thread safety MT-Safe
101 POSIX.1-2001, POSIX.1-2008.
104 .BR clock_gettime (2)
105 with the clock ID obtained by a call to
106 .BR clock_getcpuclockid ()
110 is the same as using the clock ID
111 .BR CLOCK_PROCESS_CPUTIME_ID .
113 The example program below obtains the
114 CPU-time clock ID of the process whose ID is given on the command line,
116 .BR clock_gettime (2)
117 to obtain the time on that clock.
118 An example run is the following:
122 .RB "$" " ./a.out 1" " # Show CPU clock of init process"
123 CPU-time clock for PID 1 is 2.213466748 seconds
129 #define _XOPEN_SOURCE 600
136 main(int argc, char *argv[])
142 fprintf(stderr, "%s <process\-ID>\\n", argv[0]);
146 if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
147 perror("clock_getcpuclockid");
151 if (clock_gettime(clockid, &ts) == \-1) {
152 perror("clock_gettime");
156 printf("CPU-time clock for PID %s is %ld.%09ld seconds\\n",
157 argv[1], (long) ts.tv_sec, (long) ts.tv_nsec);
162 .BR clock_getres (2),
163 .BR timer_create (2),
164 .BR pthread_getcpuclockid (3),