1 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH CLOCK_GETCPUCLOCKID 3 2010-09-10 "Linux" "Linux Programmer's Manual"
26 clock_getcpuclockid \- obtain ID of a process CPU-time clock
31 .BI "int clock_getcpuclockid(pid_t " pid ", clockid_t *" clock_id );
34 Link with \fI\-lrt\fP.
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
42 .BR clock_getcpuclockid ():
44 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
49 .BR clock_getcpuclockid ()
50 function obtains the ID of the CPU-time clock of the process whose ID is
52 and returns it in the location pointed to by
56 is zero, then the clock ID of the CPU-time clock
57 of the calling process is returned.
60 .BR clock_getcpuclockid ()
62 on error, it returns one of the positive error numbers listed in ERRORS.
66 The kernel does not support obtaining the per-process
67 CPU-time clock of another process, and
69 does not specify the calling process.
72 The caller does not have permission to access
73 the CPU-time clock of the process specified by
75 (Specified as an optional error in POSIX.1-2001;
76 does not occur on Linux unless the kernel does not support
77 obtaining the per-process CPU-time clock of another process.)
80 There is no process with the ID
84 .BR clock_getcpuclockid ()
85 function is available in glibc since version 2.2.
91 with the clock ID obtained by a call to
92 .BR clock_getcpuclockid ()
96 is the same as using the clock ID
97 .BR CLOCK_PROCESS_CPUTIME_ID .
99 The example program below obtains the
100 CPU-time clock ID of the process whose ID is given on the command line,
102 .BR clock_gettime (2)
103 to obtain the time on that clock.
104 An example run is the following:
108 .RB "$" " ./a.out 1" " # Show CPU clock of init process"
109 CPU-time clock for PID 1 is 2.213466748 seconds
115 #define _XOPEN_SOURCE 600
122 main(int argc, char *argv[])
128 fprintf(stderr, "%s <process-ID>\\n", argv[0]);
132 if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
133 perror("clock_getcpuclockid");
137 if (clock_gettime(clockid, &ts) == \-1) {
138 perror("clock_gettime");
142 printf("CPU-time clock for PID %s is %ld.%09ld seconds\\n",
143 argv[1], (long) ts.tv_sec, (long) ts.tv_nsec);
148 .BR clock_getres (2),
149 .BR timer_create (2),
150 .BR pthread_getcpuclockid (3),