.\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) .\" .\" %%%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) 1997 SUTO, Mitsuaki .\" and Copyright(c) 2008 Akihiro MOTOKI .\" all rights reserved. .\" Translated Thu Jun 26 20:33:01 JST 1997 .\" by SUTO, Mitsuaki .\" Updated 2008-10-03, Akihiro MOTOKI, LDP v3.10 .\" .TH GETPID 2 2014\-09\-21 Linux "Linux Programmer's Manual" .SH 名前 getpid, getppid \- プロセス ID を得る .SH 書式 \fB#include \fP .br \fB#include \fP .sp \fBpid_t getpid(void);\fP .br \fBpid_t getppid(void);\fP .SH 説明 \fBgetpid\fP() は呼び出し元のプロセスのプロセス ID を返す。(テンポラリ用のファイル名として 他と重ならない名前を生成するルーチンでしばしば使用される。) \fBgetppid\fP() は呼び出し元のプロセスの親プロセスのプロセス ID を返す。 .SH エラー これらの関数は常に成功する。 .SH 準拠 POSIX.1\-2001, 4.3BSD, SVr4. .SH 注意 .\" The following program demonstrates this "feature": .\" .\" #define _GNU_SOURCE .\" #include .\" #include .\" #include .\" #include .\" #include .\" .\" int .\" main(int argc, char *argv[]) .\" { .\" /* The following statement fills the getpid() cache */ .\" .\" printf("parent PID = %ld\n", (long) getpid()); .\" .\" if (syscall(SYS_fork) == 0) { .\" if (getpid() != syscall(SYS_getpid)) .\" printf("child getpid() mismatch: getpid()=%ld; " .\" "syscall(SYS_getpid)=%ld\n", .\" (long) getpid(), (long) syscall(SYS_getpid)); .\" exit(EXIT_SUCCESS); .\" } .\" wait(NULL); .\"} glibc バージョン 2.3.4 以降では、 glibc の \fBgetpid\fP() のラッパー関数は PID をキャッシュする。 これは、プロセスが繰り返し \fBgetpid\fP() を呼び出した場合にその都度システムコールを呼ぶのを避けるためである。 通常は、このキャッシュ処理が見えることはないが、 キャッシュ処理が正しく働くためには \fBfork\fP(2), \fBvfork\fP(2), \fBclone\fP(2) のラッパー関数でのサポートが必要である。 アプリケーションがこれらのシステムコールを呼び出す際に、 glibc のラッパー関数を経由せずに \fBsyscall\fP(2) を使った場合には、子プロセスで \fBgetpid\fP() を呼び出すと間違った値が返ることだろう (正確にいうと、親プロセスの PID が返される)。 \fBclone\fP(2) を glibc のラッパー関数経由で起動した際にも \fBgetpid\fP() が間違った値を返す場合があり、これに関する議論は \fBclone\fP(2) も参照してほしい。 .SH 関連項目 \fBclone\fP(2), \fBfork\fP(2), \fBkill\fP(2), \fBexec\fP(3), \fBmkstemp\fP(3), \fBtempnam\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3), \fBcredentials\fP(7), \fBpid_namespaces\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。