OSDN Git Service

LDP: Address fuzzy changes (unistd)
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / fork.2
1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" A few fragments remain from an earlier (1992) page by
3 .\" Drew Eckhardt (drew@cs.colorado.edu),
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
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 .\"*******************************************************************
40 .\"
41 .\" This file was generated with po4a. Translate the source file.
42 .\"
43 .\"*******************************************************************
44 .\"
45 .\" Japanese Version Copyright (c) 1996 TABATA Tomohira
46 .\"         all rights reserved.
47 .\" Translated Thu Jun 27 20:35:06 JST 1996
48 .\"         by TABATA Tomohira <loba@k2.t.u-tokyo.ac.jp>
49 .\" Modified Sun Dec 14 00:43:22 JST 1997
50 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
51 .\" Modified Tue Jul 10 05:36:22 JST 2001
52 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>, LDP v1.38
53 .\" Updated & Modified Wed Dec 29 12:33:12 JST 2004
54 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v2.01
55 .\" Updated & Modified Wed Jan  3 04:11:03 JST 2007 by Yuichi SATO, LDP v2.43
56 .\" Updated 2008-08-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
57 .\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
58 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
59 .\"
60 .TH FORK 2 2020\-06\-09 Linux "Linux Programmer's Manual"
61 .SH 名前
62 fork \- 子プロセスを生成する
63 .SH 書式
64 \fB#include <sys/types.h>\fP
65 .br
66 \fB#include <unistd.h>\fP
67 .PP
68 \fBpid_t fork(void);\fP
69 .SH 説明
70 \fBfork\fP()
71 は呼び出し元プロセスを複製して新しいプロセスを生成する。新しいプロセスは「子」プロセスと呼ばれ、呼び出し元プロセスは「親」プロセスと呼ばれる。
72 .PP
73 The child process and the parent process run in separate memory spaces.  At
74 the time of \fBfork\fP()  both memory spaces have the same content.  Memory
75 writes, file mappings (\fBmmap\fP(2)), and unmappings (\fBmunmap\fP(2))  performed
76 by one of the processes do not affect the other.
77 .PP
78 The child process is an exact duplicate of the parent process except for the
79 following points:
80 .IP * 3
81 The child has its own unique process ID, and this PID does not match the ID
82 of any existing process group (\fBsetpgid\fP(2))  or session.
83 .IP *
84 子プロセスの親プロセス ID は、親プロセスのプロセス ID と同じである。
85 .IP *
86 子プロセスは親プロセスのメモリーロック (\fBmlock\fP(2), \fBmlockall\fP(2))  を引き継がない。
87 .IP *
88 プロセスの資源利用量 (\fBgetrusage\fP(2))  と CPU タイムカウンター (\fBtimes\fP(2))  が、子プロセスでは 0
89 にリセットされる。
90 .IP *
91 子プロセスの処理待ちのシグナルの集合 (\fBsigpending\fP(2))  は、初期状態では空になる。
92 .IP *
93 子プロセスは親プロセスからセマフォ調整 (\fBsemop\fP(2))  を引き継がない。
94 .IP *
95 子プロセスは親プロセスからプロセスに関連付けられたレコードロックを引き継がない (\fBfcntl\fP(2))。 (一方、子プロセスは親プロセスから
96 \fBfcntl\fP(2) オープンファイル記述ロックと \fBflock\fP(2) ロックを引き継ぐ。)
97 .IP *
98 子プロセスは親プロセスからタイマー (\fBsetitimer\fP(2), \fBalarm\fP(2), \fBtimer_create\fP(2))
99 を引き継がない。
100 .IP *
101 子プロセスは親プロセスから主だった非同期 I/O 操作を引き継がない (\fBaio_read\fP(3), \fBaio_write\fP(3)  参照)。
102 また、親プロセスから非同期 I/O コンテキストを引き継がない (\fBio_setup\fP(2)  参照)。
103 .PP
104 上記のリストにあるプロセス属性は、POSIX.1 で全て指定されている。 親プロセスと子プロセスは、以下の Linux 固有のプロセス属性も異なる:
105 .IP * 3
106 子プロセスは親プロセスからディレクトリ変更通知 (dnotify)  (\fBfcntl\fP(2)  における \fBF_NOTIFY\fP の説明を参照)
107 を引き継がない。
108 .IP *
109 \fBprctl\fP(2)  の \fBPR_SET_PDEATHSIG\fP の設定がリセットされ、子プロセスは親プロセスが終了したときに
110 シグナルを受信しない。
111 .IP *
112 timer slack value のデフォルト値には、親プロセスの現在の timer slack value が設定される。 \fBprctl\fP(2)
113 の \fBPR_SET_TIMERSLACK\fP の説明を参照。
114 .IP *
115 \fBmadvise\fP(2)  の \fBMADV_DONTFORK\fP フラグでマークされたメモリーマッピングは、 \fBfork\fP()
116 によって引き継がれない。
117 .IP *
118 Memory in address ranges that have been marked with the \fBmadvise\fP(2)
119 \fBMADV_WIPEONFORK\fP flag is zeroed in the child after a \fBfork\fP().  (The
120 \fBMADV_WIPEONFORK\fP setting remains in place for those address ranges in the
121 child.)
122 .IP *
123 子プロセスの終了シグナルは常に \fBSIGCHLD\fP である (\fBclone\fP(2)  を参照)。
124 .IP *
125 \fBioperm\fP(2) で設定されるポートアクセス許可ビットは、子プロセスには継承されない。子プロセスでは、 \fBioperm\fP(2)
126 を使って必要なビットをセットしなければならない。
127 .PP
128 以下の点についても注意すること:
129 .IP * 3
130 子プロセスはシングルスレッドで生成される。つまり、 \fBfork\fP()  を呼び出したスレッドとなる。
131 親プロセスの仮想アドレス空間全体が子プロセスに複製される。 これにはミューテックス (mutex) の状態・条件変数・ pthread
132 オブジェクトが含まれる。 これが引き起こす問題を扱うには、 \fBpthread_atfork\fP(3)  を使うと良いだろう。
133 .IP *
134 After a \fBfork\fP()  in a multithreaded program, the child can safely call
135 only async\-signal\-safe functions (see \fBsignal\-safety\fP(7))  until such time
136 as it calls \fBexecve\fP(2).
137 .IP *
138 子プロセスは親プロセスが持つ オープンファイルディスクリプターの集合のコピーを引き継ぐ。 子プロセスの各ファイルディスクリプターは、
139 親プロセスのファイルディスクリプターに対応する 同じオープンファイル記述 (file description) を参照する (\fBopen\fP(2)
140 を参照)。 これは 2 つのファイルディスクリプターが、ファイル状態フラグ・ ファイルオフセット、シグナル駆動 (signal\-driven) I/O
141 属性 (\fBfcntl\fP(2)  における \fBF_SETOWN\fP, \fBF_SETSIG\fP の説明を参照) を共有することを意味する。
142 .IP *
143 子プロセスは親プロセスが持つオープンメッセージキューディスクリプター (\fBmq_overview\fP(7)  を参照) の集合のコピーを引き継ぐ。
144 子プロセスの各ファイルディスクリプターは、 親プロセスのファイルディスクリプターに対応する同じオープンメッセージキューディスクリプターを参照する。
145 これは 2 つのファイルディスクリプターが同じフラグ (\fImq_flags\fP)  を共有することを意味する。
146 .IP *
147 子プロセスは、親プロセスのオープン済みのディレクトリストリームの集合 (\fBopendir\fP(3)  参照) のコピーを継承する。 POSIX.1
148 では、親プロセスと子プロセス間の対応するディレクトリストリーム はディレクトリストリームの位置 (positioning)
149 を共有してもよいとされている。 Linux/glibc ではディレクトリストリームの位置の共有は行われていない。
150 .SH 返り値
151 成功した場合、親プロセスには子プロセスの PID が返され、 子プロセスには 0 が返される。 失敗した場合、親プロセスに \-1
152 が返され、子プロセスは生成されず、 \fIerrno\fP が適切に設定される。
153 .SH エラー
154 .TP 
155 \fBEAGAIN\fP
156 .\" NOTE! The following should match the description in pthread_create(3)
157 A system\-imposed limit on the number of threads was encountered.  There are
158 a number of limits that may trigger this error:
159 .RS
160 .IP * 3
161 the \fBRLIMIT_NPROC\fP soft resource limit (set via \fBsetrlimit\fP(2)), which
162 limits the number of processes and threads for a real user ID, was reached;
163 .IP *
164 the kernel's system\-wide limit on the number of processes and threads,
165 \fI/proc/sys/kernel/threads\-max\fP, was reached (see \fBproc\fP(5));
166 .IP *
167 the maximum number of PIDs, \fI/proc/sys/kernel/pid_max\fP, was reached (see
168 \fBproc\fP(5)); or
169 .IP *
170 the PID limit (\fIpids.max\fP)  imposed by the cgroup "process number" (PIDs)
171 controller was reached.
172 .RE
173 .TP 
174 \fBEAGAIN\fP
175 呼び出し元は、スケジューリングポリシー \fBSCHED_DEADLINE\fP で動作しており、かつ reset\-on\-fork
176 フラグがセットされていない。 \fBsched\fP(7) 参照。
177 .TP 
178 \fBENOMEM\fP
179 メモリーが足りないために、 \fBfork\fP()  は必要なカーネル構造体を割り当てることができなかった。
180 .TP 
181 \fBENOMEM\fP
182 An attempt was made to create a child process in a PID namespace whose
183 "init" process has terminated.  See \fBpid_namespaces\fP(7).
184 .TP 
185 \fBENOSYS\fP
186 .\" e.g., arm (optionally), blackfin, c6x, frv, h8300, microblaze, xtensa
187 \fBfork\fP() はこのプラットフォームではサポートされていない
188 (例えば、メモリー管理ユニット (MMU) がないハードウェア)。
189 .TP 
190 \fBERESTARTNOINTR\fP (Linux 2.6.17 以降)
191 .\" commit 4a2c7a7837da1b91468e50426066d988050e4d56
192 System call was interrupted by a signal and will be restarted.  (This can be
193 seen only during a trace.)
194 .SH 準拠
195  POSIX.1\-2001, POSIX.1\-2008, SVr4, 4.3BSD.
196 .SH 注意
197 Linux では、 \fBfork\fP()  を 書き込み時コピー (copy\-on\-write) ページを用いて実装している。 したがって、fork
198 を行うことの唯一のデメリットは、 親プロセスのページテーブルを複製と 子プロセス自身のタスク構造の作成のための時間とメモリーが必要なことである。
199 .SS "C ライブラリとカーネルの違い"
200 .\" nptl/sysdeps/unix/sysv/linux/fork.c
201 .\" and does some magic to ensure that getpid(2) returns the right value.
202 glibc 2.3.3 以降では、 NPTL スレッド実装の一部として提供されている
203 glibc の\fBfork\fP() ラッパー関数は、 カーネルの \fBfork\fP() システムコール
204 を起動するのではなく、\fBclone\fP(2) を起動する。
205 \fBclone\fP(2) に渡すフラグとして、伝統的な \fBfork\fP() システムコールと
206 同じ効果が得られるようなフラグが指定される (\fBfork\fP() の呼び出しは、
207 \fIflags\fP に \fBSIGCHLD\fP だけを指定して \fBclone\fP(2) を呼び出すのと等価である)。
208 glibc のラッパー関数は \fBpthread_atfork\fP(3) を使って設定されている
209 任意の fork ハンドラーを起動する。
210 .SH 例
211 \fBpipe\fP(2)  および \fBwait\fP(2)  を参照。
212 .SH 関連項目
213  \fBclone\fP(2), \fBexecve\fP(2), \fBexit\fP(2), \fBsetrlimit\fP(2), \fBunshare\fP(2),
214 \fBvfork\fP(2), \fBwait\fP(2), \fBdaemon\fP(3), \fBpthread_atfork\fP(3),
215 \fBcapabilities\fP(7), \fBcredentials\fP(7)
216 .SH この文書について
217 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
218 \%https://www.kernel.org/doc/man\-pages/ に書かれている。