getpidのヘルプ・マニュアル
日本語 英語
getpid --help
man getpid
GETPID(2) Linux Programmer’s Manual GETPID(2)
名前
getpid, getppid - プロセス ID を得る
書式
#include
#include
pid_t getpid(void);
pid_t getppid(void);
説明
getpid() は呼び出し元のプロセスのプロセス ID を返す。(テンポラリ用のフ
ァイル名として他と重ならない名前を生成するルーチンでしばしば使用され る
。)
getppid() は呼び出し元のプロセスの親プロセスのプロセス ID を返す。
エラー
これらの関数は常に成功する。
準拠
POSIX.1-2001, 4.3BSD, SVr4.
注意
glibc バ ージョン 2.3.4 以降では、 glibc の getpid() のラッパー関数は
PID をキャッシュする。これは、プロセスが繰り返し getpid() を呼び出し た
場 合にその都度システムコールを呼ぶのを避けるためである。通常は、このキ
ャッシュ処理が見えることはないが、キャッシュ処理が正しく働くた め に は
fork(2), vfork(2), clone(2) のラッパー関数でのサポートが必要である。ア
プリケーションがこれらのシステムコールを呼び出す際に、 glibc のラッパー
関 数を経由せずに syscall(2) を使った場合には、子プロセスで getpid() を
呼び出すと間違った値が返ることだろう (正確にいうと、親プロセスの PID が
返 さ れる)。 clone(2) を glibc のラッパー関数経由で起動した際にも get-
pid() が間違った値を返す場合があり、これに関する議論は clone(2) も参 照
してほしい。
関連項目
clone(2), fork(2), kill(2), exec(3), mkstemp(3), tempnam(3), tmp-
file(3), tmpnam(3), credentials(7)
Linux 2008-09-23 GETPID(2)
GETPID(2) Linux Programmer’s Manual GETPID(2)
NAME
getpid, getppid - get process identification
SYNOPSIS
#include
#include
pid_t getpid(void);
pid_t getppid(void);
DESCRIPTION
getpid() returns the process ID of the calling process. (This is often
used by routines that generate unique temporary filenames.)
getppid() returns the process ID of the parent of the calling process.
ERRORS
These functions are always successful.
CONFORMING TO
POSIX.1-2001, 4.3BSD, SVr4.
NOTES
Since glibc version 2.3.4, the glibc wrapper function for getpid()
caches PIDs, so as to avoid additional system calls when a process
calls getpid() repeatedly. Normally this caching is invisible, but its
correct operation relies on support in the wrapper functions for
fork(2), vfork(2), and clone(2): if an application bypasses the glibc
wrappers for these system calls by using syscall(2), then a call to
getpid() in the child will return the wrong value (to be precise: it
will return the PID of the parent process). See also clone(2) for dis-
cussion of a case where getpid() may return the wrong value even when
invoking clone(2) via the glibc wrapper function.
SEE ALSO
clone(2), fork(2), kill(2), exec(3), mkstemp(3), tempnam(3), tmp-
file(3), tmpnam(3), credentials(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-09-23 GETPID(2)