1 .\" Hey Emacs! This file is -*- nroff -*- source.
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),
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.
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.
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
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
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
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
52 .TH FORK 2 2009-04-27 "Linux" "Linux Programmer's Manual"
56 .B #include <unistd.h>
61 は呼び出し元プロセスを複製して新しいプロセスを生成する。
62 \fIchild\fP で参照される新しいプロセスは、以下の点を除き、
63 \fIparent\fP で参照される呼び出し元プロセスの完全な複製である:
70 子プロセスの親プロセス ID は、親プロセスのプロセス ID と同じである。
101 子プロセスは親プロセスから主だった非同期 I/O 操作を引き継がない
105 また、親プロセスから非同期 I/O コンテキストを引き継がない
109 上記のリストにあるプロセス属性は、POSIX.1-2001 で全て指定されている。
110 親プロセスと子プロセスは、以下の Linux 固有のプロセス属性も異なる:
112 子プロセスは親プロセスからディレクトリ変更通知 (dnotify)
121 の設定がリセットされ、子プロセスは親プロセスが終了したときに
139 子プロセスはシングルスレッドで生成される。つまり、
142 親プロセスの仮想アドレス空間全体が子プロセスに複製される。
143 これにはミューテックス (mutex) の状態・条件変数・
146 .BR pthread_atfork (3)
150 オープンファイルディスクリプタの集合のコピーを引き継ぐ。
152 親プロセスのファイルディスクリプタに対応する
153 同じオープンファイル記述 (file description) を参照する
156 これは 2 つのディスクリプタが、ファイル状態フラグ・
157 現在のファイルオフセット、シグナル駆動 (signal-driven) I/O 属性
162 の説明を参照) を共有することを意味する。
164 子プロセスは親プロセスが持つオープンメッセージキューディスクリプタ
165 .RB ( mq_overview (7)
169 同じオープンメッセージキューディスクリプタを参照する。
170 これは 2 つのディスクリプタが同じフラグ
174 子プロセスは、親プロセスのオープン済みのディレクトリストリームの集合
177 POSIX.1-2001 では、親プロセスと子プロセス間の対応するディレクトリストリーム
178 はディレクトリストリームの位置 (positioning) を共有してもよいとされている。
179 Linux/glibc ではディレクトリストリームの位置の共有は行われていない。
181 成功した場合、親プロセスには子プロセスの PID が返され、
183 失敗した場合、親プロセスに \-1 が返され、子プロセスは生成されず、
190 子プロセスのタスク構造に生成に必要なメモリを
197 資源の制限 (resource limit) に達したために、新しいプロセスを生成できなかった。
202 ケーパビリティ (capability) を持っていなくてはならない。
207 は必要なカーネル構造体を割り当てることができなかった。
209 SVr4, 4.3BSD, POSIX.1-2001.
213 を 書き込み時コピー (copy-on-write)・ページを用いて実装している。
214 したがって、fork を行うことの唯一のデメリットは、
216 子プロセス自身のタスク構造の作成のための時間とメモリが必要なことである。
219 NPTL スレッド実装の一部として提供されている glibc の
230 システムコールと同じ効果が得られるようなフラグが指定される。
232 .BR pthread_atfork (3)
233 を使って設定されている任意の fork ハンドラを起動する。
234 .\" getpid(2) が正しい値を返すことができるように何らかの処理を行う。
249 .BR capabilities (7),