.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" Copyright (c) 1992 Drew Eckhardt , March 28, 1992 .\" and Copyright (c) Michael Kerrisk, 2001, 2002, 2005 .\" May be distributed under the GNU General Public License. .\" Modified by Michael Haardt .\" Modified 24 Jul 1993 by Rik Faith .\" Modified 21 Aug 1994 by Michael Chastain : .\" New man page (copied from 'fork.2'). .\" Modified 10 June 1995 by Andries Brouwer .\" Modified 25 April 1998 by Xavier Leroy .\" Modified 26 Jun 2001 by Michael Kerrisk .\" Mostly upgraded to 2.4.x .\" Added prototype for sys_clone() plus description .\" Added CLONE_THREAD with a brief description of thread groups .\" Added CLONE_PARENT and revised entire page remove ambiguity .\" between "calling process" and "parent process" .\" Added CLONE_PTRACE and CLONE_VFORK .\" Added EPERM and EINVAL error codes .\" Renamed "__clone" to "clone" (which is the prototype in ) .\" various other minor tidy ups and clarifications. .\" Modified 26 Jun 2001 by Michael Kerrisk .\" Updated notes for 2.4.7+ behavior of CLONE_THREAD .\" Modified 15 Oct 2002 by Michael Kerrisk .\" Added description for CLONE_NEWNS, which was added in 2.4.19 .\" Slightly rephrased, aeb. .\" Modified 1 Feb 2003 - added CLONE_SIGHAND restriction, aeb. .\" Modified 1 Jan 2004 - various updates, aeb .\" Modified 2004-09-10 - added CLONE_PARENT_SETTID etc. - aeb. .\" 2005-04-12, mtk, noted the PID caching behavior of NPTL's getpid() .\" wrapper under BUGS. .\" 2005-05-10, mtk, added CLONE_SYSVSEM, CLONE_UNTRACED, CLONE_STOPPED. .\" 2005-05-17, mtk, Substantially enhanced discussion of CLONE_THREAD. .\" 2008-11-18, mtk, order CLONE_* flags alphabetically .\" 2008-11-18, mtk, document CLONE_NEWPID .\" 2008-11-19, mtk, document CLONE_NEWUTS .\" 2008-11-19, mtk, document CLONE_NEWIPC .\" 2008-11-19, Jens Axboe, mtk, document CLONE_IO .\" .\" FIXME Document CLONE_NEWUSER, which is new in 2.6.23 .\" (also supported for unshare()?) .\" FIXME . 2.6.25 marks the unused CLONE_STOPPED as obsolete, and it will .\" probably be removed in the future. .\" .\" Japanese Version Copyright (c) 2001 HANATAKA Shinya .\" and Copyright(c) 2002, 2005-2008 Akihiro MOTOKI .\" Translated 2001-08-17, HANATAKA Shinya .\" Modified 2002-09-24, Akihiro MOTOKI .\" Modified 2005-02-02, Akihiro MOTOKI .\" Updated 2005-04-17, Akihiro MOTOKI .\" Updated 2005-09-10, Akihiro MOTOKI .\" Updated 2006-03-05, Akihiro MOTOKI, LDP v2.25 .\" Updated 2007-01-05, Akihiro MOTOKI, LDP v2.43 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46 .\" Updated 2007-06-13, Akihiro MOTOKI, LDP v2.55 .\" Updated 2008-08-04, Akihiro MOTOKI, LDP v3.05 .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.10 .\" Updated 2009-03-02, Akihiro MOTOKI, LDP v3.19 .\" Updated 2010-04-11, Akihiro MOTOKI, LDP v3.24 .\" .\"WORD: capability ケーパビリティ .\"WORD: pending signals 処理待ちシグナル .\"WORD: namespace 名前空間 .\" .TH CLONE 2 2010-09-10 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .\"O clone, __clone2 \- create a child process .SH 名前 clone, __clone2 \- 子プロセスを作成する .\"O .SH SYNOPSIS .SH 書式 .nf .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */" .\" Actually _BSD_SOURCE || _SVID_SOURCE .\" See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749 .B #include .BI "int clone(int (*" "fn" ")(void *), void *" child_stack , .BI " int " flags ", void *" "arg" ", ... " .BI " /* pid_t *" ptid ", struct user_desc *" tls \ ", pid_t *" ctid " */ );" .fi .\"O .SH DESCRIPTION .SH 説明 .\"O .BR clone () .\"O creates a new process, in a manner similar to .\"O .BR fork (2). .\"O It is actually a library function layered on top of the underlying .\"O .BR clone () .\"O system call, hereinafter referred to as .\"O .BR sys_clone . .\"O A description of .\"O .B sys_clone .\"O is given toward the end of this page. .BR clone () は .BR fork (2) と同じような方法で新しいプロセスを作成する。 .BR clone () には、ライブラリ関数とその下層にあたる .BR clone () システムコールが存在する。以下の説明では、システムコールの方を .B sys_clone と表すこととする。 .B sys_clone に関する説明はこのマニュアルの最後の方にある。 .\"O Unlike .\"O .BR fork (2), .\"O these calls .\"O allow the child process to share parts of its execution context with .\"O the calling process, such as the memory space, the table of file .\"O descriptors, and the table of signal handlers. .\"O (Note that on this manual .\"O page, "calling process" normally corresponds to "parent process". .\"O But see the description of .\"O .B CLONE_PARENT .\"O below.) .BR fork (2) とは異なり、これらのコールでは、子プロセス (child process) と呼び出し元のプロセスとが、メモリ空間、 ファイルディスクリプタのテーブル、シグナル・ハンドラのテーブルなどの 実行コンテキストの一部を共有できる。 (このマニュアルにおける「呼び出し元のプロセス」は、通常は 「親プロセス」と一致する。但し、後述の .B CLONE_PARENT の項も参照のこと) .\"O The main use of .\"O .BR clone () .\"O is to implement threads: multiple threads of control in a program that .\"O run concurrently in a shared memory space. .BR clone () の主要な使用法はスレッド (threads) を実装することである: 一つのプログラムの中の複数のスレッドは共有されたメモリ空間で 同時に実行される。 .\"O When the child process is created with .\"O .BR clone (), .\"O it executes the function .\"O application .\"O .IR fn ( arg ). .\"O (This differs from .\"O .BR fork (2), .\"O where execution continues in the child from the point .\"O of the .\"O .BR fork (2) .\"O call.) .\"O The .\"O .I fn .\"O argument is a pointer to a function that is called by the child .\"O process at the beginning of its execution. .\"O The .\"O .I arg .\"O argument is passed to the .\"O .I fn .\"O function. .BR clone () で子プロセスが作成された時に、作成された子プロセスは関数 .IR fn ( arg ) を実行する。 (この点が .BR fork (2) とは異なる。 .BR fork (2) の場合、子プロセスは .BR fork (2) が呼び出された場所から実行を続ける。) .I fn 引き数は、子プロセスが実行を始める時に子プロセスが呼び出す 関数へのポインタである。 .I arg 引き数はそのまま .I fn 関数へと渡される。 .\"O When the .\"O .IR fn ( arg ) .\"O function application returns, the child process terminates. .\"O The integer returned by .\"O .I fn .\"O is the exit code for the child process. .\"O The child process may also terminate explicitly by calling .\"O .BR exit (2) .\"O or after receiving a fatal signal. .IR fn ( arg ) 関数が終了すると、子プロセスは終了する。 .I fn によって返された整数が子プロセスの終了コードとなる。 子プロセスは、 .BR exit (2) を呼んで明示的に終了することもあるし、致命的なシグナルを受信した 場合に終了することもある。 .\"O The .\"O .I child_stack .\"O argument specifies the location of the stack used by the child process. .\"O Since the child and calling process may share memory, .\"O it is not possible for the child process to execute in the .\"O same stack as the calling process. .\"O The calling process must therefore .\"O set up memory space for the child stack and pass a pointer to this .\"O space to .\"O .BR clone (). .I child_stack 引き数は、子プロセスによって使用されるスタックの位置を指定する。 子プロセスと呼び出し元のプロセスはメモリを共有することがあるため、 子プロセスは呼び出し元のプロセスと同じスタックで実行することができない。 このため、呼び出し元のプロセスは子プロセスのスタックのためのメモリ空間を 用意して、この空間へのポインタを .BR clone () へ渡さなければならない。 .\"O Stacks grow downward on all processors that run Linux .\"O (except the HP PA processors), so .\"O .I child_stack .\"O usually points to the topmost address of the memory space set up for .\"O the child stack. (HP PA プロセッサ以外の) Linux が動作する全てのプロセッサでは、 スタックは下方 (アドレスが小さい方向) へと伸びる。このため、普通は .I child_stack は子プロセスのスタックのために用意したメモリ空間の一番大きい アドレスを指すようにする。 .\"O The low byte of .\"O .I flags .\"O contains the number of the .\"O .I "termination signal" .\"O sent to the parent when the child dies. .\"O If this signal is specified as anything other than .\"O .BR SIGCHLD , .\"O then the parent process must specify the .\"O .B __WALL .\"O or .\"O .B __WCLONE .\"O options when waiting for the child with .\"O .BR wait (2). .\"O If no signal is specified, then the parent process is not signaled .\"O when the child terminates. .I flags の下位 1 バイトは子プロセスが死んだ場合に親プロセスへと送られる .I "終了シグナル (termination signal)" の番号を指定する。このシグナルとして .B SIGCHLD 以外が指定された場合、親プロセスは、 .BR wait (2) で子プロセスを待つ際に、オプションとして .B __WALL または .B __WCLONE を指定しなければならない。 どのシグナルも指定されなかった場合、子プロセスが終了した時に親プロセス にシグナルは送られない。 .\"O .I flags .\"O may also be bitwise-or'ed with zero or more of the following constants, .\"O in order to specify what is shared between the calling process .\"O and the child process: .I flags には、以下の定数のうち 0個以上をビット毎の論理和 (bitwise-or) をとったものを指定できる。これらの定数は呼び出し元のプロセスと 子プロセスの間で何を共有するかを指定する: .TP .\"O .BR CLONE_CHILD_CLEARTID " (since Linux 2.5.49)" .BR CLONE_CHILD_CLEARTID " (Linux 2.5.49 以降)" .\"O Erase child thread ID at location .\"O .I ctid .\"O in child memory when the child exits, and do a wakeup on the futex .\"O at that address. .\"O The address involved may be changed by the .\"O .BR set_tid_address (2) .\"O system call. .\"O This is used by threading libraries. 子プロセスが終了したときに子プロセスのメモリ内の .I ctid が指す場所にある子プロセスのスレッド ID を消去し、 そのアドレスで futex を wake (起床) させる。 このアドレスは .BR set_tid_address (2) システムコールで変更することができる。 この機能はスレッドライブラリで使用される。 .TP .\"O .BR CLONE_CHILD_SETTID " (since Linux 2.5.49)" .BR CLONE_CHILD_SETTID " (Linux 2.5.49 以降)" .\"O Store child thread ID at location .\"O .I ctid .\"O in child memory. 子プロセスのメモリ内の .I ctid が指す場所に子プロセスのスレッド ID を格納する。 .TP .B CLONE_FILES .\"O If .\"O .B CLONE_FILES .\"O is set, the calling process and the child process share the same file .\"O descriptor table. .\"O Any file descriptor created by the calling process or by the child .\"O process is also valid in the other process. .\"O Similarly, if one of the processes closes a file descriptor, .\"O or changes its associated flags (using the .\"O .BR fcntl (2) .\"O .B F_SETFD .\"O operation), the other process is also affected. .B CLONE_FILES が設定された場合、呼び出し元のプロセスと子プロセスはファイルディスクリプタの テーブルを共有する。 呼び出し元プロセスとその子プロセスの一方が作成した ファイルディスクリプタは、もう一方においても有効である。 同じように、一方のプロセスがファイルディスクリプタを閉じたり、 .RB ( fcntl (2) .B F_SETFD 操作を使って) ディスクリプタに関連するフラグを変更したりすると、 もう一方のプロセスにも影響する。 .\"O If .\"O .B CLONE_FILES .\"O is not set, the child process inherits a copy of all file descriptors .\"O opened in the calling process at the time of .\"O .BR clone (). .\"O (The duplicated file descriptors in the child refer to the .\"O same open file descriptions (see .\"O .BR open (2)) .\"O as the corresponding file descriptors in the calling process.) .\"O Subsequent operations that open or close file descriptors, .\"O or change file descriptor flags, .\"O performed by either the calling .\"O process or the child process do not affect the other process. .B CLONE_FILES が設定されていない場合、子プロセスは、 .BR clone () が実行された時点で、呼び出し元のプロセスがオープンしている全ての ファイルディスクリプタのコピーを継承する (子プロセスの複製されたファイルディスクリプタは、 対応する呼び出し元のプロセスのファイルディスクリプタと 同じファイル記述 .RB ( open (2) 参照) を参照する)。 これ以降に、呼び出し元のプロセスと子プロセスの一方が ファイルディスクリプタの操作 (ファイルディスクリプタの オープン・クローズや、ファイルディスクリプタ・フラグの変更) を行っても、もう一方のプロセスには影響を与えない。 .TP .B CLONE_FS .\"O If .\"O .B CLONE_FS .\"O is set, the caller and the child process share the same file system .\"O information. .\"O This includes the root of the file system, the current .\"O working directory, and the umask. .\"O Any call to .\"O .BR chroot (2), .\"O .BR chdir (2), .\"O or .\"O .BR umask (2) .\"O performed by the calling process or the child process also affects the .\"O other process. .B CLONE_FS が設定された場合、呼び出し元のプロセスと子プロセスが同じファイル・システム 情報を共有する。ファイル・システム情報は、ファイル・システムのルート (root)、 カレント・ワーキング・ディレクトリ (current working directory) や umask などである。 呼び出し元のプロセスや子プロセスのどちらか一方によって .BR chroot (2), .BR chdir (2), .BR umask (2) が呼び出されると、もう一方のプロセスにも影響が及ぶ。 .\"O If .\"O .B CLONE_FS .\"O is not set, the child process works on a copy of the file system .\"O information of the calling process at the time of the .\"O .BR clone () .\"O call. .\"O Calls to .\"O .BR chroot (2), .\"O .BR chdir (2), .\"O .BR umask (2) .\"O performed later by one of the processes do not affect the other process. .B CLONE_FS が設定されていない場合、子プロセスは、 .BR clone () が実行された時点での、呼び出し元のプロセスのファイル・システム情報のコピーを 使用する。 これ以降は、呼び出し元のプロセスと子プロセスの一方が .BR chroot (2), .BR chdir (2), .BR umask (2) を呼び出しても、もう一方のプロセスには影響を与えない。 .TP .\"O .BR CLONE_IO " (since Linux 2.6.25)" .BR CLONE_IO " (Linux 2.6.25 以降)" .\"O If .\"O .B CLONE_IO .\"O is set, then the new process shares an I/O context with .\"O the calling process. .\"O If this flag is not set, then (as with .\"O .BR fork (2)) .\"O the new process has its own I/O context. .B CLONE_IO が設定された場合、新しいプロセスは呼び出し元のプロセスと I/O コンテキストを共有する。 このフラグが設定されていない場合には、 .RB ( fork (2) の場合と同様) 新しいプロセスは自分専用の I/O コンテキストを持つ。 .\" The following based on text from Jens Axboe .\"O The I/O context is the I/O scope of the disk scheduler (i.e, .\"O what the I/O scheduler uses to model scheduling of a process's I/O). .\"O If processes share the same I/O context, .\"O they are treated as one by the I/O scheduler. .\"O As a consequence, they get to share disk time. I/O コンテキストは、ディスクスケジュールの I/O スコープである (言い換えると、I/O コンテキストは I/O スケジューラがプロセス I/O の スケジューリングをモデル化するのに使用される)。 複数のプロセスが同じ I/O コンテキストを共有する場合、 これらのプロセスは I/O スケジューラからは一つとして扱われる。 結果として、これらのプロセスはディスクアクセスの時間を共有するようになる。 .\"O For some I/O schedulers, .\"O .\" the anticipatory and CFQ scheduler .\"O if two processes share an I/O context, .\"O they will be allowed to interleave their disk access. .\"O If several threads are doing I/O on behalf of the same process .\"O .RB ( aio_read (3), .\"O for instance), they should employ .\"O .BR CLONE_IO .\"O to get better I/O performance. .\"O .\" with CFQ and AS. いくつかの I/O スケジューラでは、 .\" 予測スケジューラと CFQ スケジューラ 二つのプロセスが I/O コンテキストを共有している場合、 これらのプロセスはディスクアクセスを交互に行うことができる。 同じプロセスの複数のスレッドが I/O を実行している場合 (例えば .BR aio_read (3))、 .B CLONE_IO を利用することで I/O 性能を良くすることができる。 .\" CFQ と AS の場合 .\"O If the kernel is not configured with the .\"O .B CONFIG_BLOCK .\"O option, this flag is a no-op. カーネルの設定が .B CONFIG_BLOCK オプション付きでない場合、 このフラグは何の意味も持たない。 .TP .\"O .BR CLONE_NEWIPC " (since Linux 2.6.19)" .BR CLONE_NEWIPC " (Linux 2.6.19 以降)" .\"O If .\"O .B CLONE_NEWIPC .\"O is set, then create the process in a new IPC namespace. .\"O If this flag is not set, then (as with .\"O .BR fork (2)), .\"O the process is created in the same IPC namespace as .\"O the calling process. .\"O This flag is intended for the implementation of containers. .B CLONE_NEWIPC が設定された場合、新しい IPC 名前空間 (namespace) でプロセスを作成する。 このフラグが設定されていない場合、 .RB ( fork (2) の場合と同様) 呼び出し元のプロセスと同じ IPC 名前空間でプロセスが 作成される。 このフラグは、コンテナの実装での使用を意図して用意されたものである。 .\"O An IPC namespace consists of the set of identifiers for .\"O System V IPC objects. .\"O (These objects are created using .\"O .BR msgctl (2), .\"O .BR semctl (2), .\"O and .\"O .BR shmctl (2)). .\"O Objects created in an IPC namespace are visible to all other processes .\"O that are members of that namespace, .\"O but are not visible to processes in other IPC namespaces. IPC 名前空間は、System V IPC オブジェクト用の識別子 (identifiers) の 集合で構成される (System V IPC オブジェクトは .BR msgctl (2), .BR semctl (2), .BR shmctl (2) を使って作成される)。 ある IPC 名前空間に作成されたオブジェクトは、 その名前空間のメンバーである他のすべてのプロセスからも見えるが、 違う IPC 名前空間のプロセスからは見えない。 .\"O When an IPC namespace is destroyed .\"O (i.e, when the last process that is a member of the namespace terminates), .\"O all IPC objects in the namespace are automatically destroyed. IPC 名前空間が破棄される時 (すなわち、その名前空間のメンバーの最後のプロセスが終了する時)、 その名前空間の全ての IPC オブジェクトは自動的に破棄される。 .\"O Use of this flag requires: a kernel configured with the .\"O .B CONFIG_SYSVIPC .\"O and .\"O .B CONFIG_IPC_NS .\"O options and that the process be privileged .\"O .RB ( CAP_SYS_ADMIN ). .\"O This flag can't be specified in conjunction with .\"O .BR CLONE_SYSVSEM . このフラグを使用するためには、 カーネルでオプション .B CONFIG_SYSVIPC と .B CONFIG_IPC_NS を有効になっていること、 プロセスが特権 .RB ( CAP_SYS_ADMIN ) を持っていることが必要である。 このフラグは .B CLONE_SYSVSEM と組み合わせて使うことはできない。 .TP .\"O .BR CLONE_NEWNET " (since Linux 2.6.24)" .BR CLONE_NEWNET " (Linux 2.6.24 以降)" .\"O (The implementation of this flag is not yet complete, .\"O but probably will be mostly complete by about Linux 2.6.28.) (このフラグの実装はまだ完了していないが、 おそらく Linux 2.6.28 あたりまでにはほぼ完成することだろう。) .\"O If .\"O .B CLONE_NEWNET .\"O is set, then create the process in a new network namespace. .\"O If this flag is not set, then (as with .\"O .BR fork (2)), .\"O the process is created in the same network namespace as .\"O the calling process. .\"O This flag is intended for the implementation of containers. .B CLONE_NEWNET が設定された場合、新しいネットワーク名前空間 (network namaspace) でプロセスを作成する。 このフラグが設定されていない場合、 .RB ( fork (2) の場合と同様) 呼び出し元のプロセスと同じネットワーク名前空間でプロセスが 作成される。 このフラグは、コンテナの実装での使用を意図して用意されたものである。 .\"O A network namespace provides an isolated view of the networking stack .\"O (network device interfaces, IPv4 and IPv6 protocol stacks, .\"O IP routing tables, firewall rules, the .\"O .I /proc/net .\"O and .\"O .I /sys/class/net .\"O directory trees, sockets, etc.). .\"O A physical network device can live in exactly one .\"O network namespace. .\"O A virtual network device ("veth") pair provides a pipe-like abstraction .\"O that can be used to create tunnels between network namespaces, .\"O and can be used to create a bridge to a physical network device .\"O in another namespace. ネットワーク名前空間は、分離されたネットワークスタックを提供するものである (ネットワークスタックとは、 ネットワークデバイスインタフェース、IPv4 や IPv6 プロトコルスタック、 .IR /proc/net 、 .I /sys/class/net ディレクトリツリー、ソケットなどである)。 物理ネットワークデバイスが所属できるネットワーク名前空間は一つだけである。 仮想ネットワークデバイス ("veth") のペアにより パイプ風の抽象化 (abstraction) が実現されており、 これを使うことで、ネットワーク名前空間間のトンネルを作成したり、 別の名前空間の物理ネットワークデバイスへのブリッジを作成したり することができる。 .\"O When a network namespace is freed .\"O (i.e., when the last process in the namespace terminates), .\"O its physical network devices are moved back to the .\"O initial network namespace (not to the parent of the process). ネットワーク名前空間が解放される時 (すなわち、その名前空間の最後のプロセスが終了する時)、 物理ネットワークデバイスは初期ネットワーク名前空間 (initial network namespace) に戻される (親プロセスのネットワーク名前空間に戻される訳ではない)。 .\"O Use of this flag requires: a kernel configured with the .\"O .B CONFIG_NET_NS .\"O option and that the process be privileged .\"O .RB ( CAP_SYS_ADMIN ). このフラグを使用するためには、 カーネルでオプション .B CONFIG_NET_NS を有効になっていること、 プロセスが特権 .RB ( CAP_SYS_ADMIN ) を持っていることが必要である。 .TP .\"O .BR CLONE_NEWNS " (since Linux 2.4.19)" .BR CLONE_NEWNS " (Linux 2.4.19 以降)" .\"O Start the child in a new mount namespace. 子プロセスを新しいマウント名前空間 (mount namespace) で開始する。 .\"O Every process lives in a mount namespace. .\"O The .\"O .I namespace .\"O of a process is the data (the set of mounts) describing the file hierarchy .\"O as seen by that process. .\"O After a .\"O .BR fork (2) .\"O or .\"O .BR clone () .\"O where the .\"O .B CLONE_NEWNS .\"O flag is not set, the child lives in the same mount .\"O namespace as the parent. 各プロセスはある一つのマウント名前空間中に存在する。プロセスの .I "名前空間 (namespace)" は、そのプロセスから見えるファイル階層を表すデータ (mount の集合) である。 .B CLONE_NEWNS フラグがセットされずに .BR fork (2) か .BR clone () が呼ばれると、子プロセスは親プロセスと同じマウント名前空間に作成される。 .\"O The system calls .\"O .BR mount (2) .\"O and .\"O .BR umount (2) .\"O change the mount namespace of the calling process, and hence affect .\"O all processes that live in the same namespace, but do not affect .\"O processes in a different mount namespace. システムコール .BR mount (2)、 .BR umount (2) が呼ばれると呼び出し元のプロセスのマウント名前空間が変更され、この結果 呼び出し元のプロセスと同じ名前空間にいるプロセスはすべて影響を受けるが、 異なるマウント名前空間にいるプロセスは影響を受けない。 .\"O After a .\"O .BR clone () .\"O where the .\"O .B CLONE_NEWNS .\"O flag is set, the cloned child is started in a new mount namespace, .\"O initialized with a copy of the namespace of the parent. .B CLONE_NEWNS フラグがセットされて .BR clone () が呼ばれると、clone で作成された子プロセスは新しいマウント名前空間で 開始される。新しい名前空間は親プロセスの名前空間のコピーで初期化される。 .\"O Only a privileged process (one having the \fBCAP_SYS_ADMIN\fP capability) .\"O may specify the .\"O .B CLONE_NEWNS .\"O flag. .\"O It is not permitted to specify both .\"O .B CLONE_NEWNS .\"O and .\"O .B CLONE_FS .\"O in the same .\"O .BR clone () .\"O call. 特権プロセス (\fBCAP_SYS_ADMIN\fP ケーパビリティを持つプロセス) のみが .B CLONE_NEWNS フラグを指定することができる。 一つの .BR clone () 呼び出しで、 .B CLONE_NEWNS と .B CLONE_FS の両方を指定することはできない。 .TP .\"O .BR CLONE_NEWPID " (since Linux 2.6.24)" .BR CLONE_NEWPID " (Linux 2.6.24 以降)" .\" This explanation draws a lot of details from .\" http://lwn.net/Articles/259217/ .\" Authors: Pavel Emelyanov .\" and Kir Kolyshkin .\" .\" The primary kernel commit is 30e49c263e36341b60b735cbef5ca37912549264 .\" Author: Pavel Emelyanov .\"O If .\"O .B CLONE_NEWPID .\"O is set, then create the process in a new PID namespace. .\"O If this flag is not set, then (as with .\"O .BR fork (2)), .\"O the process is created in the same PID namespace as .\"O the calling process. .\"O This flag is intended for the implementation of containers. .B CLONE_NEWPID が設定された場合、新しい PID 名前空間でプロセスを作成する。 このフラグが設定されていない場合、 .RB ( fork (2) の場合と同様) 呼び出し元のプロセスと同じ PID 名前空間で プロセスが作成される。 このフラグは、コンテナの実装での使用を意図して用意されたものである。 .\"O A PID namespace provides an isolated environment for PIDs: .\"O PIDs in a new namespace start at 1, .\"O somewhat like a standalone system, and calls to .\"O .BR fork (2), .\"O .BR vfork (2), .\"O or .\"O .BR clone (2) .\"O will produce processes with PIDs that are unique within the namespace. PID 名前空間は、PID に関して分離された環境を提供するものである。 新しい名前空間における PID は 1 から始まり (これはスタンドアロンのシステムと似たような感じ)、 .BR fork (2), .BR vfork (2), .BR clone (2) を呼び出すと、その名前空間で一意な PID を持ったプロセスが作成される。 .\"O The first process created in a new namespace .\"O (i.e., the process created using the .\"O .BR CLONE_NEWPID .\"O flag) has the PID 1, and is the "init" process for the namespace. .\"O Children that are orphaned within the namespace will be reparented .\"O to this process rather than .\"O .BR init (8). .\"O Unlike the traditional .\"O .B init .\"O process, the "init" process of a PID namespace can terminate, .\"O and if it does, all of the processes in the namespace are terminated. 新しい名前空間で作成される最初のプロセス (つまり、 .B CLONE_NEWPID フラグを使って作成されたプロセス) の PID は 1 であり、 このプロセスはその名前空間における "init" プロセスとなる。 この名前空間において孤児 (orphaned) となった子プロセスについては、 .BR init (8) ではなくこのプロセスが親プロセスとなる。 昔ながらの .B init プロセスとは違い、PID 名前空間の "init" プロセスは終了 (terminated) する ことができ、その場合には、この名前空間の全てのプロセスが終了される。 .\"O PID namespaces form a hierarchy. PID 名前空間間には階層構造が形成される。 .\"O When a new PID namespace is created, .\"O the processes in that namespace are visible .\"O in the PID namespace of the process that created the new namespace; .\"O analogously, if the parent PID namespace is itself .\"O the child of another PID namespace, .\"O then processes in the child and parent PID namespaces will both be .\"O visible in the grandparent PID namespace. 新しい PID 名前空間が作成されると、その名前空間のプロセスは、 新しい名前空間を作成したプロセスの PID 名前空間で見える。 同様に、親の PID 名前空間自体が別の PID 名前空間の子供の場合には、 子供の PID 名前空間と親の PID 名前空間のプロセスはどれも 親の親の PID 名前空間でも見えることになる。 .\"O Conversely, the processes in the "child" PID namespace do not see .\"O the processes in the parent namespace. .\"O The existence of a namespace hierarchy means that each process .\"O may now have multiple PIDs: .\"O one for each namespace in which it is visible; .\"O each of these PIDs is unique within the corresponding namespace. .\"O (A call to .\"O .BR getpid (2) .\"O always returns the PID associated with the namespace in which .\"O the process lives.) 反対に、「子供」の PID 名前空間のプロセスには、 親の名前空間のプロセスは見えない。 名前空間に階層構造が存在するということは、個々のプロセスは 複数の PID を持つということを意味している。 そのプロセスが見える名前空間一つにつき PID が一つあり、 それぞれの PID は対応する名前空間において一意である。 .RB ( getpid (2) を呼び出すと、常にそのプロセスが存在している名前空間における PID が返される。) .\"O After creating the new namespace, .\"O it is useful for the child to change its root directory .\"O and mount a new procfs instance at .\"O .I /proc .\"O so that tools such as .\"O .BR ps (1) .\"O work correctly. 新しい名前空間の作成後には、 子プロセスにおいて、 .BR ps (1) といったツールが正しく動作するように、 自身の root ディレクトリを変更し、 .I /proc に新しい procfs インスタンスをマウントするのがよいだろう。 .\" mount -t proc proc /proc .\"O (If .\"O .BR CLONE_NEWNS .\"O is also included in .\"O .IR flags , .\"O then it isn't necessary to change the root directory: .\"O a new procfs instance can be mounted directly over .\"O .IR /proc .) .RB ( flags に .B CLONE_NEWNS も指定されていた場合には、root ディレクトリを変更する必要はなく、 いきなり新しい procfs インスタンスを .I /proc にマウントすることができる。) .\"O Use of this flag requires: a kernel configured with the .\"O .B CONFIG_PID_NS .\"O option and that the process be privileged .\"O .RB ( CAP_SYS_ADMIN ). .\"O This flag can't be specified in conjunction with .\"O .BR CLONE_THREAD . このフラグを使用するためには、 カーネルでオプション .B CONFIG_PID_NS を有効になっていること、 プロセスが特権 .RB ( CAP_SYS_ADMIN ) を持っていることが必要である。 このフラグは .B CLONE_THREAD と組み合わせて使うことはできない。 .TP .\"O .BR CLONE_NEWUTS " (since Linux 2.6.19)" .BR CLONE_NEWUTS " (Linux 2.6.19 以降)" .\"O If .\"O .B CLONE_NEWUTS .\"O is set, then create the process in a new UTS namespace, .\"O whose identifiers are initialized by duplicating the identifiers .\"O from the UTS namespace of the calling process. .\"O If this flag is not set, then (as with .\"O .BR fork (2)), .\"O the process is created in the same UTS namespace as .\"O the calling process. .\"O This flag is intended for the implementation of containers. .B CLONE_NEWUTS が設定された場合、新しい UTS 名前空間でプロセスを作成する。 新しい UTS 名前空間の識別子の初期値は、呼び出し元のプロセスの UTS 名前空間の識別子を複製したものとなる。 このフラグが設定されていない場合、 .RB ( fork (2) の場合と同様) 呼び出し元のプロセスと同じ UTS 名前空間で プロセスが作成される。 このフラグは、コンテナの実装での使用を意図して用意されたものである。 .\"O A UTS namespace is the set of identifiers returned by .\"O .BR uname (2); .\"O among these, the domain name and the host name can be modified by .\"O .BR setdomainname (2) .\"O and .\"O .BR .\"O .BR sethostname (2), .\"O respectively. .\"O Changes made to the identifiers in a UTS namespace .\"O are visible to all other processes in the same namespace, .\"O but are not visible to processes in other UTS namespaces. UTS 名前空間は、 .BR uname (2) が返す識別子の集合である。 識別子としてはドメイン名とホスト名があり、 それぞれ .BR setdomainname (2), .BR sethostname (2) で修正することができる。 ある UTS 名前空間における識別子の変更は同じ名前空間の他のすべての プロセスに見えるが、別の UTS 名前空間のプロセスには見えない。 .\"O Use of this flag requires: a kernel configured with the .\"O .B CONFIG_UTS_NS .\"O option and that the process be privileged .\"O .RB ( CAP_SYS_ADMIN ). このフラグを使用するためには、 カーネルでオプション .B CONFIG_UTS_NS を有効になっていること、 プロセスが特権 .RB ( CAP_SYS_ADMIN ) を持っていることが必要である。 .TP .\"O .BR CLONE_PARENT " (since Linux 2.3.12)" .BR CLONE_PARENT " (Linux 2.3.12 以降)" .\"O If .\"O .B CLONE_PARENT .\"O is set, then the parent of the new child (as returned by .\"O .BR getppid (2)) .\"O will be the same as that of the calling process. .B CLONE_PARENT が設定された場合、新しい子供の .RB ( getppid (2) で返される) 親プロセスは呼び出し元のプロセスの親プロセスと同じになる。 .\"O If .\"O .B CLONE_PARENT .\"O is not set, then (as with .\"O .BR fork (2)) .\"O the child's parent is the calling process. .B CLONE_PARENT が設定されていない場合、 .RB ( fork (2) と同様に) 呼び出し元のプロセスがその子供の親になる。 .\"O Note that it is the parent process, as returned by .\"O .BR getppid (2), .\"O which is signaled when the child terminates, so that .\"O if .\"O .B CLONE_PARENT .\"O is set, then the parent of the calling process, rather than the .\"O calling process itself, will be signaled. 子供が終了した時にシグナルが送られるのは .BR getppid (2) が返す親プロセスである点に注意すること。このため .B CLONE_PARENT が設定された場合、呼び出し元のプロセスではなく呼び出し元のプロセスの 親プロセスにシグナルが送られる。 .TP .\"O .BR CLONE_PARENT_SETTID " (since Linux 2.5.49)" .BR CLONE_PARENT_SETTID " (Linux 2.5.49 以降)" .\"O Store child thread ID at location .\"O .I ptid .\"O in parent and child memory. .\"O (In Linux 2.5.32-2.5.48 there was a flag .\"O .B CLONE_SETTID .\"O that did this.) 親プロセスと子プロセスのメモリ内の .I ptid が指す領域に子プロセスのスレッド ID を格納する。 (Linux 2.5.32-2.5.48 では、 同じことをする .B CLONE_SETTID というフラグが存在した。) .TP .\"O .BR CLONE_PID " (obsolete)" .BR CLONE_PID " (廃止予定)" .\"O If .\"O .B CLONE_PID .\"O is set, the child process is created with the same process ID as .\"O the calling process. .\"O This is good for hacking the system, but otherwise .\"O of not much use. .\"O Since 2.3.21 this flag can be .\"O specified only by the system boot process (PID 0). .\"O It disappeared in Linux 2.5.16. .B CLONE_PID が設定された場合、子プロセスは呼び出し元のプロセスと同じプロセス ID で作成される。これはシステムをハッキングするのには便利だが、 それ以外にはあまり使われない。 Linux 2.3.21 以降では、 システムのブートプロセス (PID 0) だけがこのフラグを指定できる。 Linux 2.5.16 で削除された。 .TP .B CLONE_PTRACE .\"O If .\"O .B CLONE_PTRACE .\"O is specified, and the calling process is being traced, .\"O then trace the child also (see .\"O .BR ptrace (2)). .B CLONE_PTRACE が指定され、かつ呼び出し元のプロセスが追跡 (trace) されていた場合、子プロセスも 同様に追跡される。 .RB ( ptrace (2) を参照のこと) .TP .\"O .BR CLONE_SETTLS " (since Linux 2.5.32)" .BR CLONE_SETTLS " (Linux 2.5.32 以降)" .\"O The .\"O .I newtls .\"O argument is the new TLS (Thread Local Storage) descriptor. .\"O (See .\"O .BR set_thread_area (2).) .I newtls 引き数は、新しい TLS (Thread Local Storage) ディスクリプタである。 .RB ( set_thread_area (2) を参照のこと) .TP .B CLONE_SIGHAND .\"O If .\"O .B CLONE_SIGHAND .\"O is set, the calling process and the child process share the same table of .\"O signal handlers. .\"O If the calling process or child process calls .\"O .BR sigaction (2) .\"O to change the behavior associated with a signal, the behavior is .\"O changed in the other process as well. .\"O However, the calling process and child .\"O processes still have distinct signal masks and sets of pending .\"O signals. .\"O So, one of them may block or unblock some signals using .\"O .BR sigprocmask (2) .\"O without affecting the other process. .B CLONE_SIGHAND が設定された場合、呼び出し元のプロセスと子プロセスは同じシグナル・ハン ドラのテーブルを共有する。呼び出し元のプロセスまたは子プロセスのどちらかが .BR sigaction (2) を呼び出してシグナルに対応する動作を変更した場合、 もう一方のプロセスのシグナル動作も変更される。 但し、呼び出し元のプロセスと子プロセスは、 プロセス毎に、シグナル・マスク (signal mask) と処理待ちシグナルの集合 を持っている。このため、あるプロセスは、 .BR sigprocmask (2) を使用して、もう一方のプロセスに影響を与えずに シグナルを禁止 (block) したり許可 (unblock) したりできる。 .\"O If .\"O .B CLONE_SIGHAND .\"O is not set, the child process inherits a copy of the signal handlers .\"O of the calling process at the time .\"O .BR clone () .\"O is called. .\"O Calls to .\"O .BR sigaction (2) .\"O performed later by one of the processes have no effect on the other .\"O process. .B CLONE_SIGHAND が設定されていない場合、子プロセスは .BR clone () が実行された時点での、呼び出し元のプロセスのシグナル・ハンドラの コピーを継承する。これ以降は、一方のプロセスが .BR sigaction (2) を呼び出しても、もう一方のプロセスには影響を与えない。 .\"O Since Linux 2.6.0-test6, .\"O .I flags .\"O must also include .\"O .B CLONE_VM .\"O if .\"O .B CLONE_SIGHAND .\"O is specified Linux 2.6.0-test6 以降では、 .B CLONE_SIGHAND を指定する場合、 .B CLONE_VM も .I flags に含めなければならない。 .TP .\"O .BR CLONE_STOPPED " (since Linux 2.6.0-test2)" .BR CLONE_STOPPED " (Linux 2.6.0-test2 以降)" .\"O If .\"O .B CLONE_STOPPED .\"O is set, then the child is initially stopped (as though it was sent a .\"O .B SIGSTOP .\"O signal), and must be resumed by sending it a .\"O .B SIGCONT .\"O signal. .B CLONE_STOPPED が設定されると、子プロセスは最初 .RB ( SIGSTOP シグナルを送られたかのように) 停止した状態となる。 子プロセスを再開させるには .B SIGCONT シグナルを送信しなければならない。 .\"O .I "From Linux 2.6.25 this flag is deprecated." .\"O You probably never wanted to use it, .\"O you certainly shouldn't be using it, and soon it will go away. .I "Linux 2.6.25 以降、このフラグは非推奨である。" このフラグを使いたいと思うことは決してないだろうし、 確実に使わないようにすべきである。 このフラグは近いうちになくなることだろう。 .\" glibc 2.8 removed this defn from bits/sched.h .TP .\"O .BR CLONE_SYSVSEM " (since Linux 2.5.10)" .BR CLONE_SYSVSEM " (Linux 2.5.10 以降)" .\"O If .\"O .B CLONE_SYSVSEM .\"O is set, then the child and the calling process share .\"O a single list of System V semaphore undo values (see .\"O .BR semop (2)). .\"O If this flag is not set, then the child has a separate undo list, .\"O which is initially empty. .B CLONE_SYSVSEM がセットされると、子プロセスと呼び出し元プロセスは一つの System V セマフォのアンドゥ値リスト .RB ( semop (2) 参照) を共有する。このフラグがセットされていなければ、 子プロセスは独自のアンドゥリストを持つ (リストの初期値は空である)。 .TP .\"O .BR CLONE_THREAD " (since Linux 2.4.0-test8)" .BR CLONE_THREAD " (Linux 2.4.0-test8以降)" .\"O If .\"O .B CLONE_THREAD .\"O is set, the child is placed in the same thread group as the calling process. .\"O To make the remainder of the discussion of .\"O .B CLONE_THREAD .\"O more readable, the term "thread" is used to refer to the .\"O processes within a thread group. .B CLONE_THREAD が設定された場合、子プロセスは呼び出し元のプロセスと同じスレッド・グループに 置かれる。 .B CLONE_THREAD についての以降の議論を読みやすくするため、 「スレッド」という用語はスレッド・グループの中のプロセスを 参照するのに使うこととする。 .\"O Thread groups were a feature added in Linux 2.4 to support the .\"O POSIX threads notion of a set of threads that share a single PID. .\"O Internally, this shared PID is the so-called .\"O thread group identifier (TGID) for the thread group. .\"O Since Linux 2.4, calls to .\"O .BR getpid (2) .\"O return the TGID of the caller. スレッド・グループは、 スレッド集合で一つの PID を共有するという POSIX スレッドの概念をサポートするために Linux 2.4 に加えられた機能であった。 内部的には、この共有 PID はいわゆるそのスレッドグループの スレッド・グループ識別子 (TGID) である。 Linux 2.4 以降では、 .BR getpid (2) の呼び出しではそのプロセスのスレッド・グループ ID を返す。 .\"O The threads within a group can be distinguished by their (system-wide) .\"O unique thread IDs (TID). .\"O A new thread's TID is available as the function result .\"O returned to the caller of .\"O .BR clone (), .\"O and a thread can obtain .\"O its own TID using .\"O .BR gettid (2). あるグループに属するスレッドは (システム全体で) 一意なスレッド ID (TID) で区別できる。新しいスレッドの TID は .BR clone () の呼び出し元へ関数の結果として返され、 スレッドは自分自身の TID を .BR gettid (2) で取得できる。 .\"O When a call is made to .\"O .BR clone () .\"O without specifying .\"O .BR CLONE_THREAD , .\"O then the resulting thread is placed in a new thread group .\"O whose TGID is the same as the thread's TID. .\"O This thread is the .\"O .I leader .\"O of the new thread group. .B CLONE_THREAD を指定せずに .BR clone () の呼び出しが行われると、 生成されたスレッドはそのスレッドの TID と同じ値の TGID を持つ 新しいスレッド・グループに置かれる。このスレッドは 新しいスレッド・グループの「リーダー」である。 .\"O A new thread created with .\"O .B CLONE_THREAD .\"O has the same parent process as the caller of .\"O .BR clone () .\"O (i.e., like .\"O .BR CLONE_PARENT ), .\"O so that calls to .\"O .BR getppid (2) .\"O return the same value for all of the threads in a thread group. .B CLONE_THREAD を指定して作成された新しいスレッドは、 .RB ( CLONE_PARENT の場合と同様に) .BR clone () を呼び出し元と同じ親プロセスを持つ。 そのため、 .BR getppid (2) を呼ぶと、一つのスレッド・グループに属すスレッドは全て同じ値を返す。 .\"O When a .\"O .B CLONE_THREAD .\"O thread terminates, the thread that created it using .\"O .BR clone () .\"O is not sent a .\"O .B SIGCHLD .\"O (or other termination) signal; .\"O nor can the status of such a thread be obtained .\"O using .\"O .BR wait (2). .\"O (The thread is said to be .\"O .IR detached .) .B CLONE_THREAD で作られたスレッドが終了した際に、 そのスレッドを .BR clone (2) を使って生成したスレッドには .B SIGCHLD (もしくは他の終了シグナル) は送信されない。 また、 .BR wait (2) を使って終了したスレッドの状態を取得することもできない (そのようなスレッドは .I detached (分離された) といわれる)。 .\"O After all of the threads in a thread group terminate .\"O the parent process of the thread group is sent a .\"O .B SIGCHLD .\"O (or other termination) signal. スレッド・グループに属す全てのスレッドが終了した後、 そのスレッド・グループの親プロセスに .B SIGCHLD (もしくは他の終了シグナル) が送られる。 .\"O If any of the threads in a thread group performs an .\"O .BR execve (2), .\"O then all threads other than the thread group leader are terminated, .\"O and the new program is executed in the thread group leader. スレッド・グループに属すいずれかのスレッドが .BR execve (2) を実行すると、スレッド・グループ・リーダー以外の全てのスレッドは 終了され、新しいプロセスがそのスレッド・グループ・リーダーの下で 実行される。 .\"O If one of the threads in a thread group creates a child using .\"O .BR fork (2), .\"O then any thread in the group can .\"O .BR wait (2) .\"O for that child. スレッド・グループに属すスレッドの一つが .BR fork (2) を使って子プロセスを作成した場合、 スレッド・グループのどのスレッドであっても その子供を .BR wait (2) できる。 .\"O Since Linux 2.5.35, .\"O .I flags .\"O must also include .\"O .B CLONE_SIGHAND .\"O if .\"O .B CLONE_THREAD .\"O is specified. Linux 2.5.35 以降では、 .B CLONE_THREAD を指定する場合、 .I flags に .B CLONE_SIGHAND も含まれていなければならない。 .\"O Signals may be sent to a thread group as a whole (i.e., a TGID) using .\"O .BR kill (2), .\"O or to a specific thread (i.e., TID) using .\"O .BR tgkill (2). .BR kill (2) を使ってスレッド・グループ全体 (つまり TGID) にシグナルを送ることもできれば、 .BR tgkill (2) を使って特定のスレッド (つまり TID) にシグナルを送ることもできる。 .\"O Signal dispositions and actions are process-wide: .\"O if an unhandled signal is delivered to a thread, then .\"O it will affect (terminate, stop, continue, be ignored in) .\"O all members of the thread group. シグナルの配送と処理はプロセス全体に影響する: ハンドラを設定していないシグナルがあるスレッドに配送されると、 そのシグナルはスレッド・グループの全メンバーに影響を及ぼす (終了したり、停止したり、動作を継続したり、無視されたりする)。 .\"O Each thread has its own signal mask, as set by .\"O .BR sigprocmask (2), .\"O but signals can be pending either: for the whole process .\"O (i.e., deliverable to any member of the thread group), .\"O when sent with .\"O .BR kill (2); .\"O or for an individual thread, when sent with .\"O .BR tgkill (2). .\"O A call to .\"O .BR sigpending (2) .\"O returns a signal set that is the union of the signals pending for the .\"O whole process and the signals that are pending for the calling thread. 各々のスレッドは独自のシグナルマスクを持っており、 .BR sigprocmask (2) で設定できる。 だが、処理待ちのシグナルには、 .BR kill (2) で送信されるプロセス全体に対するもの (つまり、スレッド・グループの どのメンバーにも配送できるもの) と、 .BR tgkill (2) で送信される個々のスレッドに対するものがありえる。 .BR sigpending (2) を呼び出すと、プロセス全体に対する処理待ちシグナルと呼び出し元の スレッドに対する処理待ちシグナルを結合したシグナル集合が返される。 .\"O If .\"O .BR kill (2) .\"O is used to send a signal to a thread group, .\"O and the thread group has installed a handler for the signal, then .\"O the handler will be invoked in exactly one, arbitrarily selected .\"O member of the thread group that has not blocked the signal. .\"O If multiple threads in a group are waiting to accept the same signal using .\"O .BR sigwaitinfo (2), .\"O the kernel will arbitrarily select one of these threads .\"O to receive a signal sent using .\"O .BR kill (2). .BR kill (2) を使ってスレッド・グループにシグナルが送られた場合で、 そのスレッド・グループがそのシグナルに対するシグナル・ハンドラが 登録されていたときには、シグナル・ハンドラはスレッド・グループの メンバーのうち、ただ一つのスレッドでだけ起動される。ハンドラが 起動されるスレッドは、そのシグナルを禁止 (block) していない メンバーの中から一つだけが勝手に (arbitrarily) 選ばれる。 スレッド・グループに属す複数のスレッドが .BR sigwaitinfo (2) を使って同じシグナルを待っている場合、 これらのスレッドの中から一つをカーネルが勝手に選択し、 そのスレッドが .B kill (2) を使って送信されたシグナルを受信する。 .TP .\"O .BR CLONE_UNTRACED " (since Linux 2.5.46)" .BR CLONE_UNTRACED " (Linux 2.5.46 以降)" .\"O If .\"O .B CLONE_UNTRACED .\"O is specified, then a tracing process cannot force .\"O .B CLONE_PTRACE .\"O on this child process. .B CLONE_UNTRACED が指定されると、 trace を行っているプロセスは この子プロセスに .B CLONE_PTRACE を適用することができない。 .TP .B CLONE_VFORK .\"O If .\"O .B CLONE_VFORK .\"O is set, the execution of the calling process is suspended .\"O until the child releases its virtual memory .\"O resources via a call to .\"O .BR execve (2) .\"O or .\"O .BR _exit (2) .\"O (as with .\"O .BR vfork (2)). .B CLONE_VFORK が設定された場合、 .RB ( vfork (2) と同様に) 子プロセスが .BR execve (2) または .BR _exit (2) によって仮想メモリを解放するまで、呼び出し元のプロセスの実行は停止される。 .\"O If .\"O .B CLONE_VFORK .\"O is not set then both the calling process and the child are schedulable .\"O after the call, and an application should not rely on execution occurring .\"O in any particular order. .B CLONE_VFORK が設定されていない場合、 .BR clone () 呼び出し後は、呼び出し元のプロセスと子プロセスの 両方がスケジュール対象となり、アプリケーションはこれらのプロセスの 実行順序に依存しないようにすべきである。 .TP .B CLONE_VM .\"O If .\"O .B CLONE_VM .\"O is set, the calling process and the child process run in the same memory .\"O space. .\"O In particular, memory writes performed by the calling process .\"O or by the child process are also visible in the other process. .\"O Moreover, any memory mapping or unmapping performed with .\"O .BR mmap (2) .\"O or .\"O .BR munmap (2) .\"O by the child or calling process also affects the other process. .B CLONE_VM が設定された場合、呼び出し元のプロセスと子プロセスは同じメモリ空間で 実行される。特に、呼び出し元のプロセスや子プロセスの一方がメモリに 書き込んだ内容はもう一方のプロセスからも見ることができる。さらに、 子プロセスや呼び出し元のプロセスの一方が .BR mmap (2) や .BR munmap (2) を使ってメモリをマップしたりアンマップした場合、 もう一方のプロセスにも影響が及ぶ。 .\"O If .\"O .B CLONE_VM .\"O is not set, the child process runs in a separate copy of the memory .\"O space of the calling process at the time of .\"O .BR clone (). .\"O Memory writes or file mappings/unmappings performed by one of the .\"O processes do not affect the other, as with .\"O .BR fork (2). .B CLONE_VM が設定されていない場合、子プロセスは .BR clone () が実行された時点での、親プロセスのメモリ空間をコピーした 別のメモリ空間で実行される。 一方のプロセスが行ったメモリへの書き込みや ファイルのマップ/アンマップは、 .BR fork (2) の場合と同様、もう一方のプロセスには影響しない。 .SS "sys_clone" .\"O The .\"O .B sys_clone .\"O system call corresponds more closely to .\"O .BR fork (2) .\"O in that execution in the child continues from the point of the .\"O call. .\"O Thus, .\"O .B sys_clone .\"O only requires the .\"O .I flags .\"O and .\"O .I child_stack .\"O arguments, which have the same meaning as for .\"O .BR clone (). .\"O (Note that the order of these arguments differs from .\"O .BR clone ().) .B sys_clone システムコールは、より .BR fork (2) に近いかたちになっており、子プロセスの実行が呼び出しが行われた場所から 続けられる。 そのため、 .B sys_clone が必要とする引き数は .I flags と .I child_stack だけであり、それらは .BR clone () と同じ意味を持つ (これらの引き数の順番は .BR clone () とは異なることに注意せよ)。 .\"O Another difference for .\"O .B sys_clone .\"O is that the .\"O .I child_stack .\"O argument may be zero, in which case copy-on-write semantics ensure that the .\"O child gets separate copies of stack pages when either process modifies .\"O the stack. .\"O In this case, for correct operation, the .\"O .B CLONE_VM .\"O option should not be specified. .B sys_clone のもう一つの違いは、 .I child_stack 引き数がゼロでも良いことである。この場合には、どちらかのプロセスが スタックを変更した時に、書き込み時コピー (copy-on-write) 方式により 子プロセスがスタック・ページの独立したコピーを得られることが保証される。 この場合、正常に動作させるためには、 .B CLONE_VM オプションを指定してはならない。 .\"O In Linux 2.4 and earlier, .\"O .BR clone () .\"O does not take arguments .\"O .IR ptid , .\"O .IR tls , .\"O and .\"O .IR ctid . Linux 2.4 以前では、 .BR clone () は引き数 .IR ptid , .IR tls , .IR ctid を取らない。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O .\" gettid(2) returns current->pid; .\"O .\" getpid(2) returns current->tgid; .\"O On success, the thread ID of the child process is returned .\"O in the caller's thread of execution. .\"O On failure, \-1 is returned .\"O in the caller's context, no child process will be created, and .\"O .I errno .\"O will be set appropriately. .\" gettid(2) は current->pid を返す .\" getpid(2) は current->tgid を返す 成功した場合、呼び出し元の実行スレッドには子プロセスのスレッドID が返される。 失敗した場合、 呼び出し元のコンテキストには \-1 が返され、子プロセスは 作成されず、 .I errno が適切に設定される。 .\"O .SH ERRORS .SH エラー .TP .B EAGAIN .\"O Too many processes are already running. すでに実行中のプロセスが多すぎる。 .TP .B EINVAL .\"O .B CLONE_SIGHAND .\"O was specified, but .\"O .B CLONE_VM .\"O was not. .\"O (Since Linux 2.6.0-test6.) .B CLONE_SIGHAND が指定されていたが、 .B CLONE_VM が指定されていなかった。 (Linux 2.6.0-test6 以降) .TP .B EINVAL .\"O .B CLONE_THREAD .\"O was specified, but .\"O .B CLONE_SIGHAND .\"O was not. .\"O (Since Linux 2.5.35.) .B CLONE_THREAD が指定されていたが、 .B CLONE_SIGHAND が指定されていなかった。 (Linux 2.5.35 以降) .\" .TP .\" .B EINVAL .\"O .\" Precisely one of .\"O .\" .B CLONE_DETACHED .\"O .\" and .\"O .\" .B CLONE_THREAD .\"O .\" was specified. .\"O .\" (Since Linux 2.6.0-test6.) .\" .B CLONE_DETACHED .\" と .\" .B CLONE_THREAD .\" のいずれか一方だけが指定された。 .\" (Linux 2.6.0-test6 以降) .TP .B EINVAL .\"O Both .\"O .B CLONE_FS .\"O and .\"O .B CLONE_NEWNS .\"O were specified in .\"O .IR flags . .B CLONE_FS と .B CLONE_NEWNS の両方が .I flags に指定された。 .TP .B EINVAL .\"O Both .\"O .B CLONE_NEWIPC .\"O and .\"O .B CLONE_SYSVSEM .\"O were specified in .\"O .IR flags . .B CLONE_NEWIPC と .B CLONE_SYSVSEM の両方が .I flags に指定された。 .TP .B EINVAL .\"O Both .\"O .BR CLONE_NEWPID .\"O and .\"O .BR CLONE_THREAD .\"O were specified in .\"O .IR flags . .B CLONE_NEWPID と .B CLONE_THREAD の両方が .I flags に指定された。 .TP .B EINVAL .\"O Returned by .\"O .BR clone () .\"O when a zero value is specified for .\"O .IR child_stack . .I child_stack にゼロを指定した場合に .BR clone () が返す。 .TP .B EINVAL .\"O .BR CLONE_NEWIPC .\"O was specified in .\"O .IR flags , .\"O but the kernel was not configured with the .\"O .B CONFIG_SYSVIPC .\"O and .\"O .BR CONFIG_IPC_NS .\"O options. .I flags に .B CLONE_NEWIPC が指定されたが、カーネルでオプション .B CONFIG_SYSVIPC と .B CONFIG_IPC_NS が有効になっていなかった。 .TP .B EINVAL .\"O .BR CLONE_NEWNET .\"O was specified in .\"O .IR flags , .\"O but the kernel was not configured with the .\"O .B CONFIG_NET_NS .\"O option. .I flags に .B CLONE_NEWNET が指定されたが、カーネルでオプション .B CONFIG_NET_NS が有効になっていなかった。 .TP .B EINVAL .\"O .BR CLONE_NEWPID .\"O was specified in .\"O .IR flags , .\"O but the kernel was not configured with the .\"O .B CONFIG_PID_NS .\"O option. .I flags に .B CLONE_NEWPID が指定されたが、カーネルでオプション .B CONFIG_PID_NS が有効になっていなかった。 .TP .B EINVAL .\"O .BR CLONE_NEWUTS .\"O was specified in .\"O .IR flags , .\"O but the kernel was not configured with the .\"O .B CONFIG_UTS .\"O option. .I flags に .B CLONE_NEWUTS が指定されたが、カーネルでオプション .B CONFIG_UTS が有効になっていなかった。 .TP .B ENOMEM .\"O Cannot allocate sufficient memory to allocate a task structure for the .\"O child, or to copy those parts of the caller's context that need to be .\"O copied. 子プロセスのために確保すべきタスク構造体や、呼び出し元のコンテキストの 一部をコピーするのに必要なメモリを十分に割り当てることができない。 .TP .B EPERM .\"O .BR CLONE_NEWIPC , .\"O .BR CLONE_NEWNET , .\"O .BR CLONE_NEWNS , .\"O .BR CLONE_NEWPID , .\"O or .\"O .BR CLONE_NEWUTS .\"O was specified by an unprivileged process (process without \fBCAP_SYS_ADMIN\fP). 非特権プロセス (\fBCAP_SYS_ADMIN\fP を持たないプロセス) が .BR CLONE_NEWIPC , .BR CLONE_NEWNET , .BR CLONE_NEWNS , .BR CLONE_NEWPID , .BR CLONE_NEWUTS を指定した。 .TP .B EPERM .\"O .B CLONE_PID .\"O was specified by a process other than process 0. PID が 0 以外のプロセスによって .B CLONE_PID が指定された。 .\"O .SH VERSIONS .SH バージョン .\"O There is no entry for .\"O .BR clone () .\"O in libc5. .\"O glibc2 provides .\"O .BR clone () .\"O as described in this manual page. libc5 には .BR clone () はない。glibc2 では .BR clone () が提供されており、このマニュアルページに記載の通りである。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O The .\"O .BR clone () .\"O and .\"O .B sys_clone .\"O calls are Linux-specific and should not be used in programs .\"O intended to be portable. .BR clone () と .B sys_clone コールは Linux 特有であり、移植を考慮したプログラムでは使用すべき ではない。 .\"O .SH NOTES .SH 注意 .\"O In the kernel 2.4.x series, .\"O .B CLONE_THREAD .\"O generally does not make the parent of the new thread the same .\"O as the parent of the calling process. .\"O However, for kernel versions 2.4.7 to 2.4.18 the .\"O .B CLONE_THREAD .\"O flag implied the .\"O .B CLONE_PARENT .\"O flag (as in kernel 2.6). カーネル 2.4.x 系列では、一般的には .B CLONE_THREAD フラグを指定しても新しいスレッドの親を 呼び出し元プロセスの親と同じにはしない。 しかし、バージョン 2.4.7〜2.4.18 のカーネルでは、 (カーネル 2.6 と同じように) CLONE_THREAD フラグを指定すると、 暗黙のうちに CLONE_PARENT フラグを指定したことになる。 .\"O For a while there was .\"O .B CLONE_DETACHED .\"O (introduced in 2.5.32): .\"O parent wants no child-exit signal. .\"O In 2.6.2 the need to give this .\"O together with .\"O .B CLONE_THREAD .\"O disappeared. .\"O This flag is still defined, but has no effect. .B CLONE_DETACHED というフラグが、2.5.32 で導入されて以来しばらくの間存在した。 このフラグは親プロセスが子プロセス終了のシグナルを必要としないことを 表すものである。 2.6.2 で、 CLONE_DETATCHED を CLONE_THREAD と一緒に指定する必要はなくなった。 このフラグはまだ定義されているが、何の効果もない。 .\"O On i386, .\"O .BR clone () .\"O should not be called through vsyscall, but directly through .\"O .IR "int $0x80" . i386 上では、 .BR clone () は vsyscall 経由ではなく、直接 .I "int $0x80" 経由で呼び出すべきである。 .\"O On ia64, a different system call is used: ia64 では、別のシステムコールが使用される: .nf .BI "int __clone2(int (*" "fn" ")(void *), " .BI " void *" child_stack_base ", size_t " stack_size , .BI " int " flags ", void *" "arg" ", ... " .BI " /* pid_t *" ptid ", struct user_desc *" tls \ ", pid_t *" ctid " */ );" .fi .PP .\"O The .\"O .BR __clone2 () .\"O system call operates in the same way as .\"O .BR clone (), .\"O except that .\"O .I child_stack_base .\"O points to the lowest address of the child's stack area, .\"O and .\"O .I stack_size .\"O specifies the size of the stack pointed to by .\"O .IR child_stack_base . .BR __clone2 () システムコールは .BR clone () と同じように動作するが、以下の点が異なる: .I child_stack_base は子プロセスのスタックエリアの最小のアドレスを指し、 .I stack_size は .I child_stack_base が指し示すスタックエリアの大きさを示す。 .\"O .SH BUGS .SH バグ .\"O Versions of the GNU C library that include the NPTL threading library .\"O contain a wrapper function for .\"O .BR getpid (2) .\"O that performs caching of PIDs. NPTL スレッド・ライブラリを含んでいる GNU C ライブラリのいくつかのバージョン には、 .BR getpid (2) のラッパー関数が含まれており、このラッパー関数は PID をキャッシュする。 .\"O This caching relies on support in the glibc wrapper for .\"O .BR clone (), .\"O but as currently implemented, .\"O the cache may not be up to date in some circumstances. このキャッシュ処理が正しく動作するためには glibc の .BR clone (2) のラッパー関数での助けが必要だが、現状の実装では、 ある状況下においてキャッシュが最新とならない可能性がある。 .\"O In particular, .\"O if a signal is delivered to the child immediately after the .\"O .BR clone () .\"O call, then a call to .\"O .BR getpid () .\"O in a handler for the signal may return the PID .\"O of the calling process ("the parent"), .\"O if the clone wrapper has not yet had a chance to update the PID .\"O cache in the child. 特に、 .BR clone () の呼び出し直後にシグナルが子プロセスに配送された場合に、 そのシグナルに対するハンドラ内で .BR getpid () を呼び出すと、それまでに clone のラッパー関数が子プロセスの PID キャッシュを 更新する機会が得られていなければ、呼び出し元プロセス ("親プロセス") の PID が 返される可能性がある。 .\"O (This discussion ignores the case where the child was created using .\"O .BR CLONE_THREAD , .\"O when .\"O .BR getpid () .\"O .I should .\"O return the same value in the child and in the process that called .\"O .BR clone (), .\"O since the caller and the child are in the same thread group. .\"O The stale-cache problem also does not occur if the .\"O .I flags .\"O argument includes .\"O .BR CLONE_VM .) (この議論では、子プロセスが .B CLONE_THREAD を使って作成された場合のことは無視している。 子プロセスが .B CLONE_THREAD を作って作成された場合には、 呼び出し元と子プロセスは同じスレッド・グループに属すので、 .BR getpid () は子プロセスと .BR clone () を呼び出したプロセスで同じ値を返すのが「正しい」。 キャッシュが最新とならない問題 (stale-cache problem) は、 .I flags に .B CLONE_VM が含まれている場合にも発生しない。) .\"O To get the truth, it may be necessary to use code such as the following: 本当の値を得るためには、次のようなコードを使う必要があるかもしれない。 .nf #include pid_t mypid; mypid = syscall(SYS_getpid); .fi .\" See also the following bug reports .\" https://bugzilla.redhat.com/show_bug.cgi?id=417521 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=6910 .\"O .SH "SEE ALSO" .SH 関連項目 .BR fork (2), .BR futex (2), .BR getpid (2), .BR gettid (2), .BR set_thread_area (2), .BR set_tid_address (2), .BR tkill (2), .BR unshare (2), .BR wait (2), .BR capabilities (7), .BR pthreads (7)