OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / man2 / getpid.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"*******************************************************************
24 .\"
25 .\" This file was generated with po4a. Translate the source file.
26 .\"
27 .\"*******************************************************************
28 .TH GETPID 2 2008\-09\-23 Linux "Linux Programmer's Manual"
29 .SH 名前
30 getpid, getppid \- プロセス ID を得る
31 .SH 書式
32 \fB#include <sys/types.h>\fP
33 .br
34 \fB#include <unistd.h>\fP
35 .sp
36 \fBpid_t getpid(void);\fP
37 .br
38 \fBpid_t getppid(void);\fP
39 .SH 説明
40 \fBgetpid\fP()  は呼び出し元のプロセスのプロセス ID を返す。(テンポラリ用のファイル名として
41 他と重ならない名前を生成するルーチンでしばしば使用される。)
42
43 \fBgetppid\fP()  は呼び出し元のプロセスの親プロセスのプロセス ID を返す。
44 .SH エラー
45 これらの関数は常に成功する。
46 .SH 準拠
47 POSIX.1\-2001, 4.3BSD, SVr4.
48 .SH 注意
49 .\" The following program demonstrates this "feature":
50 .\"
51 .\" #define _GNU_SOURCE
52 .\" #include <sys/syscall.h>
53 .\" #include <sys/wait.h>
54 .\" #include <stdio.h>
55 .\" #include <stdlib.h>
56 .\" #include <unistd.h>
57 .\"
58 .\" int
59 .\" main(int argc, char *argv[])
60 .\" {
61 .\"    /* The following statement fills the getpid() cache */
62 .\"
63 .\"    printf("parent PID = %ld\n", (long) getpid());
64 .\"
65 .\"    if (syscall(SYS_fork) == 0) {
66 .\"        if (getpid() != syscall(SYS_getpid))
67 .\"            printf("child getpid() mismatch: getpid()=%ld; "
68 .\"                    "syscall(SYS_getpid)=%ld\n",
69 .\"                    (long) getpid(), (long) syscall(SYS_getpid));
70 .\"        exit(EXIT_SUCCESS);
71 .\"    }
72 .\"    wait(NULL);
73 .\"}
74 glibc バージョン 2.3.4 以降では、 glibc の \fBgetpid\fP()  のラッパー関数は PID をキャッシュする。
75 これは、プロセスが繰り返し \fBgetpid\fP()  を呼び出した場合にその都度システムコールを呼ぶのを避けるためである。
76 通常は、このキャッシュ処理が見えることはないが、 キャッシュ処理が正しく働くためには \fBfork\fP(2), \fBvfork\fP(2),
77 \fBclone\fP(2)  のラッパー関数でのサポートが必要である。 アプリケーションがこれらのシステムコールを呼び出す際に、 glibc
78 のラッパー関数を経由せずに \fBsyscall\fP(2)  を使った場合には、子プロセスで \fBgetpid\fP()
79 を呼び出すと間違った値が返ることだろう (正確にいうと、親プロセスの PID が返される)。 \fBclone\fP(2)  を glibc
80 のラッパー関数経由で起動した際にも \fBgetpid\fP()  が間違った値を返す場合があり、これに関する議論は \fBclone\fP(2)
81 も参照してほしい。
82 .SH 関連項目
83 \fBclone\fP(2), \fBfork\fP(2), \fBkill\fP(2), \fBexec\fP(3), \fBmkstemp\fP(3),
84 \fBtempnam\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3), \fBcredentials\fP(7)