.\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk .\" .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2013 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2013-07-31, Akihiro MOTOKI .\" .TH CLOCK_GETCPUCLOCKID 3 2013\-07\-04 Linux "Linux Programmer's Manual" .SH 名前 clock_getcpuclockid \- プロセスの CPU 時刻のクロック ID を取得する .SH 書式 \fB#include \fP .nf .sp \fBint clock_getcpuclockid(pid_t \fP\fIpid\fP\fB, clockid_t *\fP\fIclock_id\fP\fB);\fP .fi .sp \fI\-lrt\fP とリンクする (バージョン 2.17 より前の glibc のみ) .sp .ad l .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBclock_getcpuclockid\fP(): .RS 4 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L .RE .ad .SH 説明 \fBclock_getcpuclockid\fP() 関数は、 プロセス ID が \fIpid\fP のプロセスの CPU 時刻のクロック ID を取得し、 その ID を \fIclock_id\fP が指す場所に入れて返す。 \fIpid\fP が 0 の場合、 呼び出し元のプロセスの CPU 時刻のクロック ID が返される。 .SH 返り値 成功すると、 \fBclock_getcpuclockid\fP() は 0 を返す。 エラーの場合、 「エラー」の節のリストにある正のエラー番号のいずれかを返す。 .SH エラー .TP \fBENOSYS\fP カーネルが他のプロセスのプロセス単位の CPU 時刻のクロックの取得に対応しておらず、 かつ \fIpid\fP が呼び出し元のプロセスを指していなかった。 .TP \fBEPERM\fP 呼び出し元プロセスが \fIpid\fP で指定されたプロセスの CPU 時刻のクロックにアクセスする許可を持っていなかった。(POSIX.1\-2001 では任意のエラーとして規定されている。 カーネルが他のプロセスのプロセス単位の CPU 時刻のクロックの取得に対応していない場合には、 このエラーは発生しない。) .TP \fBESRCH\fP ID が \fIpid\fP のプロセスが存在しない。 .SH バージョン \fBclock_getcpuclockid\fP() 関数は glibc バージョン 2.2 以降で利用可能である。 .SH 属性 .SS "マルチスレッディング (pthreads(7) 参照)" \fBclock_getcpuclockid\fP() 関数はスレッドセーフである。 .SH 準拠 POSIX.1\-2001. .SH 注意 \fIpid\fP に 0 を指定して \fBclock_getcpuclockid\fP() を呼び出して得られたクロック ID を引き数として \fBclock_gettime\fP(2) の呼び出すのは、 クロック ID \fBCLOCK_PROCESS_CPUTIME_ID\fP を使って \fBclock_gettime\fP(2) の呼び出すのと同じである。 .SH 例 以下のサンプルプログラムは、 コマンドラインで指定された ID を持つプロセスの CPU 時刻のクロック ID を取得し、 \fBclock_gettime\fP(2) を使ってそのクロックの時刻を取得する。 以下は実行例である。 .in +4n .nf $\fB ./a.out 1\fP # Show CPU clock of init process CPU\-time clock for PID 1 is 2.213466748 seconds .fi .in .SS プログラムのソース \& .nf #define _XOPEN_SOURCE 600 #include #include #include #include int main(int argc, char *argv[]) { clockid_t clockid; struct timespec ts; if (argc != 2) { fprintf(stderr, "%s \en", argv[0]); exit(EXIT_FAILURE); } if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) { perror("clock_getcpuclockid"); exit(EXIT_FAILURE); } if (clock_gettime(clockid, &ts) == \-1) { perror("clock_gettime"); exit(EXIT_FAILURE); } printf("CPU\-time clock for PID %s is %ld.%09ld seconds\en", argv[1], (long) ts.tv_sec, (long) ts.tv_nsec); exit(EXIT_SUCCESS); } .fi .SH 関連項目 \fBclock_getres\fP(2), \fBtimer_create\fP(2), \fBpthread_getcpuclockid\fP(3), \fBtime\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。