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 .\"*******************************************************************
26 .\" This file was generated with po4a. Translate the source file.
28 .\"*******************************************************************
29 .TH CLOCK_GETCPUCLOCKID 3 2010\-09\-10 Linux "Linux Programmer's Manual"
31 clock_getcpuclockid \- obtain ID of a process CPU\-time clock
33 \fB#include <time.h>\fP
36 \fBint clock_getcpuclockid(pid_t \fP\fIpid\fP\fB, clockid_t *\fP\fIclock_id\fP\fB);\fP
43 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
46 \fBclock_getcpuclockid\fP():
48 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
52 The \fBclock_getcpuclockid\fP() function obtains the ID of the CPU\-time clock
53 of the process whose ID is \fIpid\fP, and returns it in the location pointed to
54 by \fIclock_id\fP. If \fIpid\fP is zero, then the clock ID of the CPU\-time clock
55 of the calling process is returned.
57 On success, \fBclock_getcpuclockid\fP() returns 0; on error, it returns one of
58 the positive error numbers listed in ERRORS.
62 The kernel does not support obtaining the per\-process CPU\-time clock of
63 another process, and \fIpid\fP does not specify the calling process.
66 The caller does not have permission to access the CPU\-time clock of the
67 process specified by \fIpid\fP. (Specified as an optional error in
68 POSIX.1\-2001; does not occur on Linux unless the kernel does not support
69 obtaining the per\-process CPU\-time clock of another process.)
72 There is no process with the ID \fIpid\fP.
74 The \fBclock_getcpuclockid\fP() function is available in glibc since version
79 Calling \fBclock_gettime\fP(2) with the clock ID obtained by a call to
80 \fBclock_getcpuclockid\fP() with a \fIpid\fP of 0, is the same as using the clock
81 ID \fBCLOCK_PROCESS_CPUTIME_ID\fP.
83 The example program below obtains the CPU\-time clock ID of the process whose
84 ID is given on the command line, and then uses \fBclock_gettime\fP(2) to
85 obtain the time on that clock. An example run is the following:
89 $\fB ./a.out 1\fP # Show CPU clock of init process
90 CPU\-time clock for PID 1 is 2.213466748 seconds
96 #define _XOPEN_SOURCE 600
103 main(int argc, char *argv[])
109 fprintf(stderr, "%s <process\-ID>\en", argv[0]);
113 if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
114 perror("clock_getcpuclockid");
118 if (clock_gettime(clockid, &ts) == \-1) {
119 perror("clock_gettime");
123 printf("CPU\-time clock for PID %s is %ld.%09ld seconds\en",
124 argv[1], (long) ts.tv_sec, (long) ts.tv_nsec);
129 \fBclock_getres\fP(2), \fBtimer_create\fP(2), \fBpthread_getcpuclockid\fP(3),