OSDN Git Service

(split) LDP: Update draft pages
[linuxjm/LDP_man-pages.git] / draft / man3 / clock_getcpuclockid.3
1 .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
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.
8 .\"
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.
13 .\"
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
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH CLOCK_GETCPUCLOCKID 3 2013\-07\-04 Linux "Linux Programmer's Manual"
32 .SH 名前
33 clock_getcpuclockid \- obtain ID of a process CPU\-time clock
34 .SH 書式
35 \fB#include <time.h>\fP
36 .nf
37 .sp
38 \fBint clock_getcpuclockid(pid_t \fP\fIpid\fP\fB, clockid_t *\fP\fIclock_id\fP\fB);\fP
39 .fi
40 .sp
41 \fI\-lrt\fP とリンクする (バージョン 2.17 より前の glibc のみ)
42 .sp
43 .ad l
44 .in -4n
45 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
46 .in
47 .sp
48 \fBclock_getcpuclockid\fP():
49 .RS 4
50 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
51 .RE
52 .ad
53 .SH 説明
54 The \fBclock_getcpuclockid\fP()  function obtains the ID of the CPU\-time clock
55 of the process whose ID is \fIpid\fP, and returns it in the location pointed to
56 by \fIclock_id\fP.  If \fIpid\fP is zero, then the clock ID of the CPU\-time clock
57 of the calling process is returned.
58 .SH 返り値
59 On success, \fBclock_getcpuclockid\fP()  returns 0; on error, it returns one of
60 the positive error numbers listed in ERRORS.
61 .SH エラー
62 .TP 
63 \fBENOSYS\fP
64 The kernel does not support obtaining the per\-process CPU\-time clock of
65 another process, and \fIpid\fP does not specify the calling process.
66 .TP 
67 \fBEPERM\fP
68 The caller does not have permission to access the CPU\-time clock of the
69 process specified by \fIpid\fP.  (Specified as an optional error in
70 POSIX.1\-2001; does not occur on Linux unless the kernel does not support
71 obtaining the per\-process CPU\-time clock of another process.)
72 .TP 
73 \fBESRCH\fP
74 There is no process with the ID \fIpid\fP.
75 .SH バージョン
76 The \fBclock_getcpuclockid\fP()  function is available in glibc since version
77 2.2.
78 .SH 属性
79 .SS "マルチスレッディング (pthreads(7) 参照)"
80 \fBclock_getcpuclockid\fP() 関数はスレッドセーフである。
81 .SH 準拠
82 POSIX.1\-2001.
83 .SH 注意
84 Calling \fBclock_gettime\fP(2)  with the clock ID obtained by a call to
85 \fBclock_getcpuclockid\fP()  with a \fIpid\fP of 0, is the same as using the clock
86 ID \fBCLOCK_PROCESS_CPUTIME_ID\fP.
87 .SH 例
88 The example program below obtains the CPU\-time clock ID of the process whose
89 ID is given on the command line, and then uses \fBclock_gettime\fP(2)  to
90 obtain the time on that clock.  An example run is the following:
91 .in +4n
92 .nf
93
94 $\fB ./a.out 1\fP                 # Show CPU clock of init process
95 CPU\-time clock for PID 1 is 2.213466748 seconds
96 .fi
97 .in
98 .SS プログラムのソース
99 \&
100 .nf
101 #define _XOPEN_SOURCE 600
102 #include <stdio.h>
103 #include <unistd.h>
104 #include <stdlib.h>
105 #include <time.h>
106
107 int
108 main(int argc, char *argv[])
109 {
110     clockid_t clockid;
111     struct timespec ts;
112
113     if (argc != 2) {
114         fprintf(stderr, "%s <process\-ID>\en", argv[0]);
115         exit(EXIT_FAILURE);
116     }
117
118     if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
119         perror("clock_getcpuclockid");
120         exit(EXIT_FAILURE);
121     }
122
123     if (clock_gettime(clockid, &ts) == \-1) {
124         perror("clock_gettime");
125         exit(EXIT_FAILURE);
126     }
127
128     printf("CPU\-time clock for PID %s is %ld.%09ld seconds\en",
129             argv[1], (long) ts.tv_sec, (long) ts.tv_nsec);
130     exit(EXIT_SUCCESS);
131 }
132 .fi
133 .SH 関連項目
134 \fBclock_getres\fP(2), \fBtimer_create\fP(2), \fBpthread_getcpuclockid\fP(3),
135 \fBtime\fP(7)
136 .SH この文書について
137 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
138 である。プロジェクトの説明とバグ報告に関する情報は
139 http://www.kernel.org/doc/man\-pages/ に書かれている。