OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man2 / fork.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" A few fragments remain from an earlier (1992) page by
5 .\" Drew Eckhardt (drew@cs.colorado.edu),
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\" Modified by Michael Haardt (michael@moria.de)
28 .\" Modified Sat Jul 24 13:22:07 1993 by Rik Faith (faith@cs.unc.edu)
29 .\" Modified 21 Aug 1994 by Michael Chastain (mec@shell.portal.com):
30 .\"   Referenced 'clone(2)'.
31 .\" Modified 1995-06-10, 1996-04-18, 1999-11-01, 2000-12-24
32 .\"   by Andries Brouwer (aeb@cwi.nl)
33 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
34 .\"     Added notes on capability requirements
35 .\" 2006-09-04, Michael Kerrisk
36 .\"     Greatly expanded, to describe all attributes that differ
37 .\"     parent and child.
38 .\"
39 .\" Japanese Version Copyright (c) 1996 TABATA Tomohira
40 .\"         all rights reserved.
41 .\" Translated Thu Jun 27 20:35:06 JST 1996
42 .\"         by TABATA Tomohira <loba@k2.t.u-tokyo.ac.jp>
43 .\" Modified Sun Dec 14 00:43:22 JST 1997
44 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
45 .\" Modified Tue Jul 10 05:36:22 JST 2001
46 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>, LDP v1.38
47 .\" Updated & Modified Wed Dec 29 12:33:12 JST 2004
48 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v2.01
49 .\" Updated & Modified Wed Jan  3 04:11:03 JST 2007 by Yuichi SATO, LDP v2.43
50 .\" Updated 2008-08-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
51 .\"
52 .TH FORK 2 2009-04-27 "Linux" "Linux Programmer's Manual"
53 .\"O .SH NAME
54 .SH Ì¾Á°
55 .\"O fork \- create a child process
56 fork \- »Ò¥×¥í¥»¥¹¤òÀ¸À®¤¹¤ë
57 .\"O .SH SYNOPSIS
58 .SH ½ñ¼°
59 .B #include <unistd.h>
60 .sp
61 .B pid_t fork(void);
62 .\"O .SH DESCRIPTION
63 .SH ÀâÌÀ
64 .\"O .BR fork ()
65 .\"O creates a new process by duplicating the calling process.
66 .\"O The new process, referred to as the \fIchild\fP,
67 .\"O is an exact duplicate of the calling process,
68 .\"O referred to as the \fIparent\fP, except for the following points:
69 .BR fork ()
70 ¤Ï¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤òÊ£À½¤·¤Æ¿·¤·¤¤¥×¥í¥»¥¹¤òÀ¸À®¤¹¤ë¡£
71 \fIchild\fP ¤Ç»²¾È¤µ¤ì¤ë¿·¤·¤¤¥×¥í¥»¥¹¤Ï¡¢°Ê²¼¤ÎÅÀ¤ò½ü¤­¡¢
72 \fIparent\fP ¤Ç»²¾È¤µ¤ì¤ë¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Î´°Á´¤ÊÊ£À½¤Ç¤¢¤ë:
73 .IP * 3
74 .\"O The child has its own unique process ID,
75 .\"O and this PID does not match the ID of any existing process group
76 .\"O .RB ( setpgid (2)).
77 »Ò¥×¥í¥»¥¹¤ÏÆȼ«¤Î¥×¥í¥»¥¹ ID ¤ò»ý¤Á¡¢
78 ¤³¤Î PID ¤Ï´û¸¤Î¤É¤Î¥×¥í¥»¥¹¥°¥ë¡¼¥×
79 .RB ( setpgid (2))
80 ¤Î ID ¤È¤â°ìÃפ·¤Ê¤¤¡£
81 .IP *
82 .\"O The child's parent process ID is the same as the parent's process ID.
83 »Ò¥×¥í¥»¥¹¤Î¿Æ¥×¥í¥»¥¹ ID ¤Ï¡¢¿Æ¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ ID ¤ÈƱ¤¸¤Ç¤¢¤ë¡£
84 .IP *
85 .\"O The child does not inherit its parent's memory locks
86 .\"O .RB ( mlock (2),
87 .\"O .BR mlockall (2)).
88 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤Î¥á¥â¥ê¥í¥Ã¥¯
89 .RB ( mlock (2),
90 .BR mlockall (2))
91 ¤ò°ú¤­·Ñ¤¬¤Ê¤¤¡£
92 .IP *
93 .\"O Process resource utilizations
94 .\"O .RB ( getrusage (2))
95 .\"O and CPU time counters
96 .\"O .RB ( times (2))
97 .\"O are reset to zero in the child.
98 ¥×¥í¥»¥¹¤Î»ñ¸»ÍøÍÑÎÌ
99 .RB ( getrusage (2))
100 ¤È CPU ¥¿¥¤¥à¥«¥¦¥ó¥¿
101 .RB ( times (2))
102 ¤¬¡¢»Ò¥×¥í¥»¥¹¤Ç¤Ï 0 ¤Ë¥ê¥»¥Ã¥È¤µ¤ì¤ë¡£
103 .IP *
104 .\"O The child's set of pending signals is initially empty
105 .\"O .RB ( sigpending (2)).
106 »Ò¥×¥í¥»¥¹¤Î½èÍýÂÔ¤Á¤Î¥·¥°¥Ê¥ë¤Î½¸¹ç
107 .RB ( sigpending (2))
108 ¤Ï¡¢½é´ü¾õÂ֤Ǥ϶õ¤Ë¤Ê¤ë¡£
109 .IP *
110 .\"O The child does not inherit semaphore adjustments from its parent
111 .\"O .RB ( semop (2)).
112 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤«¤é¥»¥Þ¥Õ¥©Ä´À°
113 .RB ( semop (2))
114 ¤ò°ú¤­·Ñ¤¬¤Ê¤¤¡£
115 .IP *
116 .\"O The child does not inherit record locks from its parent
117 .\"O .RB ( fcntl (2)).
118 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤«¤é¥ì¥³¡¼¥É¥í¥Ã¥¯
119 .RB ( fcntl (2))
120 ¤ò°ú¤­·Ñ¤¬¤Ê¤¤¡£
121 .IP *
122 .\"O The child does not inherit timers from its parent
123 .\"O .RB ( setitimer (2),
124 .\"O .BR alarm (2),
125 .\"O .BR timer_create (2)).
126 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤«¤é¥¿¥¤¥Þ¡¼
127 .RB ( setitimer (2),
128 .BR alarm (2),
129 .BR timer_create (2))
130 ¤ò°ú¤­·Ñ¤¬¤Ê¤¤¡£
131 .IP *
132 .\"O The child does not inherit outstanding asynchronous I/O operations
133 .\"O from its parent
134 .\"O .RB ( aio_read (3),
135 .\"O .BR aio_write (3)),
136 .\"O nor does it inherit any asynchronous I/O contexts from its parent (see
137 .\"O .BR io_setup (2)).
138 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤«¤é¼ç¤À¤Ã¤¿ÈóƱ´ü I/O Áàºî¤ò°ú¤­·Ñ¤¬¤Ê¤¤
139 .RB ( aio_read (3),
140 .BR aio_write (3)
141 »²¾È)¡£
142 ¤Þ¤¿¡¢¿Æ¥×¥í¥»¥¹¤«¤éÈóƱ´ü I/O ¥³¥ó¥Æ¥­¥¹¥È¤ò°ú¤­·Ñ¤¬¤Ê¤¤
143 .RB ( io_setup (2)
144 »²¾È)¡£
145 .PP
146 .\"O The process attributes in the preceding list are all specified
147 .\"O in POSIX.1-2001.
148 .\"O The parent and child also differ with respect to the following
149 .\"O Linux-specific process attributes:
150 ¾åµ­¤Î¥ê¥¹¥È¤Ë¤¢¤ë¥×¥í¥»¥¹Â°À­¤Ï¡¢POSIX.1-2001 ¤ÇÁ´¤Æ»ØÄꤵ¤ì¤Æ¤¤¤ë¡£
151 ¿Æ¥×¥í¥»¥¹¤È»Ò¥×¥í¥»¥¹¤Ï¡¢°Ê²¼¤Î Linux ¸ÇÍ­¤Î¥×¥í¥»¥¹Â°À­¤â°Û¤Ê¤ë:
152 .IP * 3
153 .\"O The child does not inherit directory change notifications (dnotify)
154 .\"O from its parent
155 .\"O (see the description of
156 .\"O .B F_NOTIFY
157 .\"O in
158 .\"O .BR fcntl (2)).
159 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤«¤é¥Ç¥£¥ì¥¯¥È¥êÊѹ¹ÄÌÃΠ(dnotify)
160 .RB ( fcntl (2)
161 ¤Ë¤ª¤±¤ë
162 .B F_NOTIFY
163 ¤ÎÀâÌÀ¤ò»²¾È) ¤ò°ú¤­·Ñ¤¬¤Ê¤¤¡£
164 .IP *
165 .\"O The
166 .\"O .BR prctl (2)
167 .\"O .B PR_SET_PDEATHSIG
168 .\"O setting is reset so that the child does not receive a signal
169 .\"O when its parent terminates.
170 .BR prctl (2)
171 ¤Î
172 .B PR_SET_PDEATHSIG
173 ¤ÎÀßÄ꤬¥ê¥»¥Ã¥È¤µ¤ì¡¢»Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤¬½ªÎ»¤·¤¿¤È¤­¤Ë
174 ¥·¥°¥Ê¥ë¤ò¼õ¿®¤·¤Ê¤¤¡£
175 .IP *
176 .\"O Memory mappings that have been marked with the
177 .\"O .BR madvise (2)
178 .\"O .B MADV_DONTFORK
179 .\"O flag are not inherited across a
180 .\"O .BR fork ().
181 .BR madvise (2)
182 ¤Î
183 .B MADV_DONTFORK
184 ¥Õ¥é¥°¤Ç¥Þ¡¼¥¯¤µ¤ì¤¿¥á¥â¥ê¥Þ¥Ã¥Ô¥ó¥°¤Ï¡¢
185 .BR fork ()
186 ¤Ë¤è¤Ã¤Æ°ú¤­·Ñ¤¬¤ì¤Ê¤¤¡£
187 .IP *
188 .\"O The termination signal of the child is always
189 .\"O .B SIGCHLD
190 .\"O (see
191 .\"O .BR clone (2)).
192 »Ò¥×¥í¥»¥¹¤Î½ªÎ»¥·¥°¥Ê¥ë¤Ï¾ï¤Ë
193 .B SIGCHLD
194 ¤Ç¤¢¤ë
195 .RB ( clone (2)
196 ¤ò»²¾È)¡£
197 .PP
198 .\"O Note the following further points:
199 ¤µ¤é¤Ë°Ê²¼¤ÎÅÀ¤Ë¤Ä¤¤¤ÆÃí°Õ¤¹¤ë¤³¤È:
200 .IP * 3
201 .\"O The child process is created with a single thread \(em the
202 .\"O one that called
203 .\"O .BR fork ().
204 »Ò¥×¥í¥»¥¹¤Ï¥·¥ó¥°¥ë¥¹¥ì¥Ã¥É¤ÇÀ¸À®¤µ¤ì¤ë¡£¤Ä¤Þ¤ê¡¢
205 .BR fork ()
206 ¤ò¸Æ¤Ó½Ð¤·¤¿¥¹¥ì¥Ã¥É¤È¤Ê¤ë¡£
207 .\"O The entire virtual address space of the parent is replicated in the child,
208 .\"O including the states of mutexes, condition variables,
209 .\"O and other pthreads objects; the use of
210 .\"O .BR pthread_atfork (3)
211 .\"O may be helpful for dealing with problems that this can cause.
212 ¿Æ¥×¥í¥»¥¹¤Î²¾ÁÛ¥¢¥É¥ì¥¹¶õ´ÖÁ´ÂΤ¬»Ò¥×¥í¥»¥¹¤ËÊ£À½¤µ¤ì¤ë¡£
213 ¤³¤ì¤Ë¤Ï¥ß¥å¡¼¥Æ¥Ã¥¯¥¹ (mutex) ¤Î¾õÂÖ¡¦¾ò·ïÊÑ¿ô¡¦
214 pthread ¥ª¥Ö¥¸¥§¥¯¥È¤¬´Þ¤Þ¤ì¤ë¡£
215 ¤³¤ì¤¬°ú¤­µ¯¤³¤¹ÌäÂê¤ò°·¤¦¤Ë¤Ï¡¢
216 .BR pthread_atfork (3)
217 ¤ò»È¤¦¤ÈÎɤ¤¤À¤í¤¦¡£
218 .IP *
219 .\"O The child inherits copies of the parent's set of open file descriptors.
220 .\"O Each file descriptor in the child refers to the same
221 .\"O open file description (see
222 .\"O .BR open (2))
223 .\"O as the corresponding file descriptor in the parent.
224 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤¬»ý¤Ä
225 ¥ª¡¼¥×¥ó¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î½¸¹ç¤Î¥³¥Ô¡¼¤ò°ú¤­·Ñ¤°¡£
226 »Ò¥×¥í¥»¥¹¤Î³Æ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢
227 ¿Æ¥×¥í¥»¥¹¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂбþ¤¹¤ë
228 Ʊ¤¸¥ª¡¼¥×¥ó¥Õ¥¡¥¤¥ëµ­½Ò (file description) ¤ò»²¾È¤¹¤ë
229 .RB ( open (2)
230 ¤ò»²¾È)¡£
231 .\"O This means that the two descriptors share open file status flags,
232 .\"O current file offset,
233 .\"O and signal-driven I/O attributes (see the description of
234 .\"O .B F_SETOWN
235 .\"O and
236 .\"O .B F_SETSIG
237 .\"O in
238 .\"O .BR fcntl (2)).
239 ¤³¤ì¤Ï 2 ¤Ä¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬¡¢¥Õ¥¡¥¤¥ë¾õÂ֥ե饰¡¦
240 ¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¡¢¥·¥°¥Ê¥ë¶îÆ° (signal-driven) I/O Â°À­
241 .RB ( fcntl (2)
242 ¤Ë¤ª¤±¤ë
243 .BR F_SETOWN ,
244 .B F_SETSIG
245 ¤ÎÀâÌÀ¤ò»²¾È) ¤ò¶¦Í­¤¹¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
246 .IP *
247 .\"O The child inherits copies of the parent's set of open message
248 .\"O queue descriptors (see
249 .\"O .BR mq_overview (7)).
250 »Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤¬»ý¤Ä¥ª¡¼¥×¥ó¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¥Ç¥£¥¹¥¯¥ê¥×¥¿
251 .RB ( mq_overview (7)
252 ¤ò»²¾È) ¤Î½¸¹ç¤Î¥³¥Ô¡¼¤ò°ú¤­·Ñ¤°¡£
253 .\"O Each descriptor in the child refers to the same
254 .\"O open message queue description
255 .\"O as the corresponding descriptor in the parent.
256 »Ò¥×¥í¥»¥¹¤Î³Æ¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢
257 ¿Æ¥×¥í¥»¥¹¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂбþ¤¹¤ë
258 Ʊ¤¸¥ª¡¼¥×¥ó¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò»²¾È¤¹¤ë¡£
259 .\"O This means that the two descriptors share the same flags
260 .\"O .RI ( mq_flags ).
261 ¤³¤ì¤Ï 2 ¤Ä¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬Æ±¤¸¥Õ¥é¥°
262 .RI ( mq_flags )
263 ¤ò¶¦Í­¤¹¤ë¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
264 .IP *
265 .\"O The child inherits copies of the parent's set of open directory streams (see
266 .\"O .BR opendir (3)).
267 .\"O POSIX.1-2001 says that the corresponding directory streams
268 .\"O in the parent and child
269 .\"O .I may
270 .\"O share the directory stream positioning;
271 .\"O on Linux/glibc they do not.
272 »Ò¥×¥í¥»¥¹¤Ï¡¢¿Æ¥×¥í¥»¥¹¤Î¥ª¡¼¥×¥óºÑ¤ß¤Î¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤Î½¸¹ç
273 .RB ( opendir (3)
274 »²¾È) ¤Î¥³¥Ô¡¼¤ò·Ñ¾µ¤¹¤ë¡£
275 POSIX.1-2001 ¤Ç¤Ï¡¢¿Æ¥×¥í¥»¥¹¤È»Ò¥×¥í¥»¥¹´Ö¤ÎÂбþ¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à
276 ¤Ï¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤Î°ÌÃÖ (positioning) ¤ò¶¦Í­¤·¤Æ¤â¤è¤¤¤È¤µ¤ì¤Æ¤¤¤ë¡£
277 Linux/glibc ¤Ç¤Ï¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤Î°ÌÃ֤ζ¦Í­¤Ï¹Ô¤ï¤ì¤Æ¤¤¤Ê¤¤¡£
278 .\"O .SH "RETURN VALUE"
279 .SH ÊÖ¤êÃÍ
280 .\"O On success, the PID of the child process is returned in the parent,
281 .\"O and 0 is returned in the child.
282 .\"O On failure, \-1 is returned in the parent,
283 .\"O no child process is created, and
284 .\"O .I errno
285 .\"O is set appropriately.
286 À®¸ù¤·¤¿¾ì¹ç¡¢¿Æ¥×¥í¥»¥¹¤Ë¤Ï»Ò¥×¥í¥»¥¹¤Î PID ¤¬ÊÖ¤µ¤ì¡¢
287 »Ò¥×¥í¥»¥¹¤Ë¤Ï 0 ¤¬ÊÖ¤µ¤ì¤ë¡£
288 ¼ºÇÔ¤·¤¿¾ì¹ç¡¢¿Æ¥×¥í¥»¥¹¤Ë \-1 ¤¬ÊÖ¤µ¤ì¡¢»Ò¥×¥í¥»¥¹¤ÏÀ¸À®¤µ¤ì¤º¡¢
289 .I errno
290 ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
291 .\"O .SH ERRORS
292 .SH ¥¨¥é¡¼
293 .TP
294 .B EAGAIN
295 .\"O .BR fork ()
296 .\"O cannot allocate sufficient memory to copy the parent's page tables and
297 .\"O allocate a task structure for the child.
298 ¿Æ¥×¥í¥»¥¹¤Î¥Ú¡¼¥¸¡¦¥Æ¡¼¥Ö¥ë¤Î¥³¥Ô¡¼¤È
299 »Ò¥×¥í¥»¥¹¤Î¥¿¥¹¥¯¹½Â¤¤ËÀ¸À®¤ËɬÍפʥá¥â¥ê¤ò
300 .BR fork ()
301 ¤¬³ä¤êÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¡£
302 .TP
303 .B EAGAIN
304 .\"O It was not possible to create a new process because the caller's
305 .\"O .B RLIMIT_NPROC
306 .\"O resource limit was encountered.
307 ¸Æ¤Ó½Ð¤·¸µ¤Î
308 .B RLIMIT_NPROC
309 »ñ¸»¤ÎÀ©¸Â (resource limit) ¤Ë㤷¤¿¤¿¤á¤Ë¡¢¿·¤·¤¤¥×¥í¥»¥¹¤òÀ¸À®¤Ç¤­¤Ê¤«¤Ã¤¿¡£
310 .\"O To exceed this limit, the process must have either the
311 .\"O .B CAP_SYS_ADMIN
312 .\"O or the
313 .\"O .B CAP_SYS_RESOURCE
314 .\"O capability.
315 ¤³¤ÎÀ©¸Â¤òĶ¤¨¤ë¤Ë¤Ï¡¢¥×¥í¥»¥¹¤Ï
316 .B CAP_SYS_ADMIN
317 ¤Þ¤¿¤Ï
318 .B CAP_SYS_RESOURCE
319 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£ (capability) ¤ò»ý¤Ã¤Æ¤¤¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
320 .TP
321 .B ENOMEM
322 .\"O .BR fork ()
323 .\"O failed to allocate the necessary kernel structures because memory is tight.
324 ¥á¥â¥ê¤¬Â­¤ê¤Ê¤¤¤¿¤á¤Ë¡¢
325 .BR fork ()
326 ¤ÏɬÍפʥ«¡¼¥Í¥ë¹½Â¤ÂΤò³ä¤êÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¡£
327 .\"O .SH "CONFORMING TO"
328 .SH ½àµò
329 SVr4, 4.3BSD, POSIX.1-2001.
330 .\"O .SH NOTES
331 .SH Ãí°Õ
332 .\"O .PP
333 .\"O Under Linux,
334 .\"O .BR fork ()
335 .\"O is implemented using copy-on-write pages, so the only penalty that it incurs
336 .\"O is the time and memory required to duplicate the parent's page tables,
337 .\"O and to create a unique task structure for the child.
338 Linux ¤Ç¤Ï¡¢
339 .BR fork ()
340 ¤ò ½ñ¤­¹þ¤ß»þ¥³¥Ô¡¼ (copy-on-write)¡¦¥Ú¡¼¥¸¤òÍѤ¤¤Æ¼ÂÁõ¤·¤Æ¤¤¤ë¡£
341 ¤·¤¿¤¬¤Ã¤Æ¡¢fork ¤ò¹Ô¤¦¤³¤È¤ÎÍ£°ì¤Î¥Ç¥á¥ê¥Ã¥È¤Ï¡¢
342 ¿Æ¥×¥í¥»¥¹¤Î¥Ú¡¼¥¸¡¦¥Æ¡¼¥Ö¥ë¤òÊ£À½¤È
343 »Ò¥×¥í¥»¥¹¼«¿È¤Î¥¿¥¹¥¯¹½Â¤¤ÎºîÀ®¤Î¤¿¤á¤Î»þ´Ö¤È¥á¥â¥ê¤¬É¬Íפʤ³¤È¤Ç¤¢¤ë¡£
344
345 .\"O Since version 2.3.3,
346 .\"O .\" nptl/sysdeps/unix/sysv/linux/fork.c
347 .\"O rather than invoking the kernel's
348 .\"O .BR fork ()
349 .\"O system call,
350 .\"O the glibc
351 .\"O .BR fork ()
352 .\"O wrapper that is provided as part of the
353 .\"O NPTL threading implementation invokes
354 .\"O .BR clone (2)
355 .\"O with flags that provide the same effect as the traditional system call.
356 .\"O The glibc wrapper invokes any fork handlers that have been
357 .\"O established using
358 .\"O .BR pthread_atfork (3).
359 .\"O .\" and does some magic to ensure that getpid(2) returns the right value.
360 glibc 2.3.3 °Ê¹ß¤Ç¤Ï¡¢
361 NPTL ¥¹¥ì¥Ã¥É¼ÂÁõ¤Î°ìÉô¤È¤·¤ÆÄ󶡤µ¤ì¤Æ¤¤¤ë glibc ¤Î
362 .BR fork ()
363 ¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï¡¢
364 ¥«¡¼¥Í¥ë¤Î
365 .BR fork ()
366 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤òµ¯Æ°¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢
367 .BR clone (2)
368 ¤òµ¯Æ°¤¹¤ë¡£
369 .BR clone (2)
370 ¤ËÅϤ¹¥Õ¥é¥°¤È¤·¤Æ¡¢ÅÁÅýŪ¤Ê
371 .BR fork ()
372 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÈƱ¤¸¸ú²Ì¤¬ÆÀ¤é¤ì¤ë¤è¤¦¤Ê¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤ë¡£
373 glibc ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï
374 .BR pthread_atfork (3)
375 ¤ò»È¤Ã¤ÆÀßÄꤵ¤ì¤Æ¤¤¤ëǤ°Õ¤Î fork ¥Ï¥ó¥É¥é¤òµ¯Æ°¤¹¤ë¡£
376 .\" getpid(2) ¤¬Àµ¤·¤¤ÃͤòÊÖ¤¹¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë²¿¤é¤«¤Î½èÍý¤ò¹Ô¤¦¡£
377
378 .\"O .SH EXAMPLE
379 .SH Îã
380 .\"O See
381 .\"O .BR pipe (2)
382 .\"O and
383 .\"O .BR wait (2).
384 .BR pipe (2)
385 ¤ª¤è¤Ó
386 .BR wait (2)
387 ¤ò»²¾È¡£
388 .\"O .SH "SEE ALSO"
389 .SH ´ØÏ¢¹àÌÜ
390 .BR clone (2),
391 .BR execve (2),
392 .BR setrlimit (2),
393 .BR unshare (2),
394 .BR vfork (2),
395 .BR wait (2),
396 .BR daemon (3),
397 .BR capabilities (7),
398 .BR credentials (7)