1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
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 .\" Japanese Version Copyright (c) 1997 SUTO, Mitsuaki
25 .\" and Copyright(c) 2008 Akihiro MOTOKI
26 .\" all rights reserved.
27 .\" Translated Thu Jun 26 20:33:01 JST 1997
28 .\" by SUTO, Mitsuaki <suto@av.crl.sony.co.jp>
29 .\" Updated 2008-10-03, Akihiro MOTOKI, LDP v3.10
31 .TH GETPID 2 2008-09-23 "Linux" "Linux Programmer's Manual"
34 .\"O getpid, getppid \- get process identification
35 getpid, getppid \- プロセス ID を得る
38 .B #include <sys/types.h>
40 .B #include <unistd.h>
42 .B pid_t getpid(void);
44 .B pid_t getppid(void);
48 .\"O returns the process ID of the calling process.
49 .\"O (This is often used by
50 .\"O routines that generate unique temporary filenames.)
52 は呼び出し元のプロセスのプロセス ID を返す。(テンポラリ用のファイル名として
53 他と重ならない名前を生成するルーチンでしばしば使用される。)
56 .\"O returns the process ID of the parent of the calling process.
58 は呼び出し元のプロセスの親プロセスのプロセス ID を返す。
61 .\"O These functions are always successful.
63 .\"O .SH "CONFORMING TO"
65 POSIX.1-2001, 4.3BSD, SVr4.
68 .\"O Since glibc version 2.3.4,
69 .\"O the glibc wrapper function for
72 .\"O so as to avoid additional system calls when a process calls
75 glibc バージョン 2.3.4 以降では、
78 のラッパー関数は PID をキャッシュする。
81 を呼び出した場合にその都度システムコールを呼ぶのを避けるためである。
82 .\"O Normally this caching is invisible,
83 .\"O but its correct operation relies on support in the wrapper functions for
88 .\"O if an application bypasses the glibc wrappers for these system calls by using
92 .\"O in the child will return the wrong value
93 .\"O (to be precise: it will return the PID of the parent process).
94 通常は、このキャッシュ処理が見えることはないが、
100 アプリケーションがこれらのシステムコールを呼び出す際に、
106 (正確にいうと、親プロセスの PID が返される)。
107 .\" The following program demonstrates this "feature":
109 .\" #define _GNU_SOURCE
110 .\" #include <sys/syscall.h>
111 .\" #include <sys/wait.h>
112 .\" #include <stdio.h>
113 .\" #include <stdlib.h>
114 .\" #include <unistd.h>
117 .\" main(int argc, char *argv[])
119 .\" /* The following statement fills the getpid() cache */
121 .\" printf("parent PID = %ld\n", (long) getpid());
123 .\" if (syscall(SYS_fork) == 0) {
124 .\" if (getpid() != syscall(SYS_getpid))
125 .\" printf("child getpid() mismatch: getpid()=%ld; "
126 .\" "syscall(SYS_getpid)=%ld\n",
127 .\" (long) getpid(), (long) syscall(SYS_getpid));
128 .\" exit(EXIT_SUCCESS);
134 .\"O for discussion of a case where
136 .\"O may return the wrong value even when invoking
138 .\"O via the glibc wrapper function.
140 を glibc のラッパー関数経由で起動した際にも
142 が間違った値を返す場合があり、これに関する議論は