OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / 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 .\" 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
30 .\"
31 .TH GETPID 2 2008-09-23 "Linux" "Linux Programmer's Manual"
32 .\"O .SH NAME
33 .SH Ì¾Á°
34 .\"O getpid, getppid \- get process identification
35 getpid, getppid \- ¥×¥í¥»¥¹ ID ¤òÆÀ¤ë
36 .\"O .SH SYNOPSIS
37 .SH ½ñ¼°
38 .B #include <sys/types.h>
39 .br
40 .B #include <unistd.h>
41 .sp
42 .B pid_t getpid(void);
43 .br
44 .B pid_t getppid(void);
45 .\"O .SH DESCRIPTION
46 .SH ÀâÌÀ
47 .\"O .BR getpid ()
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.)
51 .BR getpid ()
52 ¤Ï¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ ID ¤òÊÖ¤¹¡£(¥Æ¥ó¥Ý¥é¥êÍѤΥե¡¥¤¥ë̾¤È¤·¤Æ
53 ¾¤È½Å¤Ê¤é¤Ê¤¤Ì¾Á°¤òÀ¸À®¤¹¤ë¥ë¡¼¥Á¥ó¤Ç¤·¤Ð¤·¤Ð»ÈÍѤµ¤ì¤ë¡£)
54
55 .\"O .BR getppid ()
56 .\"O returns the process ID of the parent of the calling process.
57 .BR getppid ()
58 ¤Ï¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î¿Æ¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ ID ¤òÊÖ¤¹¡£
59 .\"O .SH ERRORS
60 .SH ¥¨¥é¡¼
61 .\"O These functions are always successful.
62 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¾ï¤ËÀ®¸ù¤¹¤ë¡£
63 .\"O .SH "CONFORMING TO"
64 .SH ½àµò
65 POSIX.1-2001, 4.3BSD, SVr4.
66 .\"O .SH NOTES
67 .SH Ãí°Õ
68 .\"O Since glibc version 2.3.4,
69 .\"O the glibc wrapper function for
70 .\"O .BR getpid ()
71 .\"O caches PIDs,
72 .\"O so as to avoid additional system calls when a process calls
73 .\"O .BR getpid ()
74 .\"O repeatedly.
75 glibc ¥Ð¡¼¥¸¥ç¥ó 2.3.4 °Ê¹ß¤Ç¤Ï¡¢
76 glibc ¤Î
77 .BR getpid ()
78 ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï PID ¤ò¥­¥ã¥Ã¥·¥å¤¹¤ë¡£
79 ¤³¤ì¤Ï¡¢¥×¥í¥»¥¹¤¬·«¤êÊÖ¤·
80 .BR getpid ()
81 ¤ò¸Æ¤Ó½Ð¤·¤¿¾ì¹ç¤Ë¤½¤ÎÅÔÅÙ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¸Æ¤Ö¤Î¤òÈò¤±¤ë¤¿¤á¤Ç¤¢¤ë¡£
82 .\"O Normally this caching is invisible,
83 .\"O but its correct operation relies on support in the wrapper functions for
84 .\"O .BR fork (2),
85 .\"O .BR vfork (2),
86 .\"O and
87 .\"O .BR clone (2):
88 .\"O if an application bypasses the glibc wrappers for these system calls by using
89 .\"O .BR syscall (2),
90 .\"O then a call to
91 .\"O .BR getpid ()
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 Ä̾ï¤Ï¡¢¤³¤Î¥­¥ã¥Ã¥·¥å½èÍý¤¬¸«¤¨¤ë¤³¤È¤Ï¤Ê¤¤¤¬¡¢
95 ¥­¥ã¥Ã¥·¥å½èÍý¤¬Àµ¤·¤¯Æ¯¤¯¤¿¤á¤Ë¤Ï
96 .BR fork (2),
97 .BR vfork (2),
98 .BR clone (2)
99 ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ç¤Î¥µ¥Ý¡¼¥È¤¬É¬ÍפǤ¢¤ë¡£
100 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë¡¢
101 glibc ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤ò·Ðͳ¤»¤º¤Ë
102 .BR syscall (2)
103 ¤ò»È¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢»Ò¥×¥í¥»¥¹¤Ç
104 .BR getpid ()
105 ¤ò¸Æ¤Ó½Ð¤¹¤È´Ö°ã¤Ã¤¿Ãͤ¬Ê֤뤳¤È¤À¤í¤¦
106 (Àµ³Î¤Ë¤¤¤¦¤È¡¢¿Æ¥×¥í¥»¥¹¤Î PID ¤¬ÊÖ¤µ¤ì¤ë)¡£
107 .\" The following program demonstrates this "feature":
108 .\"
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>
115 .\"
116 .\" int
117 .\" main(int argc, char *argv[])
118 .\" {
119 .\"    /* The following statement fills the getpid() cache */
120 .\"
121 .\"    printf("parent PID = %ld\n", (long) getpid());
122 .\"
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);
129 .\"    }
130 .\"    wait(NULL);
131 .\"}
132 .\"O See also
133 .\"O .BR clone (2)
134 .\"O for discussion of a case where
135 .\"O .BR getpid ()
136 .\"O may return the wrong value even when invoking
137 .\"O .BR clone (2)
138 .\"O via the glibc wrapper function.
139 .BR clone (2)
140 ¤ò glibc ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô·Ðͳ¤Çµ¯Æ°¤·¤¿ºÝ¤Ë¤â
141 .BR getpid ()
142 ¤¬´Ö°ã¤Ã¤¿ÃͤòÊÖ¤¹¾ì¹ç¤¬¤¢¤ê¡¢¤³¤ì¤Ë´Ø¤¹¤ëµÄÏÀ¤Ï
143 .BR clone (2)
144 ¤â»²¾È¤·¤Æ¤Û¤·¤¤¡£
145 .\"O .SH "SEE ALSO"
146 .SH ´ØÏ¢¹àÌÜ
147 .BR clone (2),
148 .BR fork (2),
149 .BR kill (2),
150 .BR exec (3),
151 .BR mkstemp (3),
152 .BR tempnam (3),
153 .BR tmpfile (3),
154 .BR tmpnam (3),
155 .BR credentials (7)