.\" Copyright (c) 1983, 1991 Regents of the University of California. .\" and Copyright (C) 2007, Michael Kerrisk .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getpgrp.2 6.4 (Berkeley) 3/10/91 .\" .\" Modified 1993-07-24 by Rik Faith .\" Modified 1995-04-15 by Michael Chastain : .\" Added 'getpgid'. .\" Modified 1996-07-21 by Andries Brouwer .\" Modified 1996-11-06 by Eric S. Raymond .\" Modified 1999-09-02 by Michael Haardt .\" Modified 2002-01-18 by Michael Kerrisk .\" Modified 2003-01-20 by Andries Brouwer .\" 2007-07-25, mtk, fairly substantial rewrites and rearrangements .\" of text. .\" .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya .\" all rights reserved. .\" Translated Sun Nov 21 18:54:10 JST 1999 .\" by HANATAKA Shinya .\" Updated Fri Feb 7 JST 2003 by Kentaro Shirakata .\" Updated Sun Feb 23 JST 2003 by Kentaro Shirakata .\" Updated 2007-09-25, Akihiro MOTOKI , LDP v2.64 .\" Updated 2010-04-23, Akihiro MOTOKI, LDP v3.24 .\" .\"WORD: process group プロセスグループ .\"WORD: process group ID プロセスグループ ID .\"WORD: terminal 端末 .\"WORD: foreground フォアグランド .\"WORD: block 中断(block) .\"WORD: job control ジョブ・コントロール .\" .TH SETPGID 2 2010-09-26 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O setpgid, getpgid, setpgrp, getpgrp \- set/get process group setpgid, getpgid, setpgrp, getpgrp \- プロセスグループの設定/取得を行う .\"O .SH SYNOPSIS .SH 書式 .B #include .sp .BI "int setpgid(pid_t " pid ", pid_t " pgid ); .br .BI "pid_t getpgid(pid_t " pid ); .sp .BR "pid_t getpgrp(void);" " /* POSIX.1 version */" .br .BI "pid_t getpgrp(pid_t " pid ");\ \ \ \ \ \ \ \ \ \ \ " /* BSD version */ .sp .BR "int setpgrp(void);" " /* System V version */" .br .BI "int setpgrp(pid_t " pid ", pid_t " pgid ");\ " /* BSD version */ .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .ad l .PD 0 .BR getpgid (): .RS 4 _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .br .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L .RE .sp .BR setpgrp "() (POSIX.1):" .nf _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .fi .sp .BR setpgrp "()\ (BSD)," .BR getpgrp "()\ (BSD):" .nf _BSD_SOURCE && !\ (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE || _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE) .fi .PD .ad .\"O .SH DESCRIPTION .SH 説明 .\"O All of these interfaces are available on Linux, .\"O and are used for getting and setting the .\"O process group ID (PGID) of a process. .\"O The preferred, POSIX.1-specified ways of doing this are: .\"O .BR getpgrp (void), .\"O for retrieving the calling process's PGID; and .\"O .BR setpgid (), .\"O for setting a process's PGID. これらのインタフェースすべてが Linux で利用可能で、 これらを使ってプロセスのプロセスグループ ID (PGID) の 取得や設定ができる。 推奨の、POSIX.1 で規定された方法では、 .BR getpgrp (void) で呼び出し元プロセスの PGID を取得し、 .BR setpgid () で設定する。 .\"O .BR setpgid () .\"O sets the PGID of the process specified by .\"O .I pid .\"O to .\"O .IR pgid . .\"O If .\"O .I pid .\"O is zero, then the process ID of the calling process is used. .\"O If .\"O .I pgid .\"O is zero, then the PGID of the process specified by .\"O .I pid .\"O is made the same as its process ID. .BR setpgid () は .I pid で指定したプロセスの PGID に .I pgid を設定する。 .I pid がゼロならば、呼び出し元プロセスのプロセス ID が pid として使用される。 .I pgid がゼロならば、 .I pid で指定されたプロセスの PGID がそのプロセスのプロセス ID と 同じに設定される。 .\"O If .\"O .BR setpgid () .\"O is used to move a process from one process .\"O group to another (as is done by some shells when creating pipelines), .\"O both process groups must be part of the same session (see .\"O .BR setsid (2) .\"O and .\"O .BR credentials (7)). .\"O In this case, .\"O the \fIpgid\fP specifies an existing process group to be joined and the .\"O session ID of that group must match the session ID of the joining process. .BR setpgid () をプロセスをあるプロセスグループから別のグループへ 移動するために使用する場合は (一部のシェルはパイプラインを生成 する時にこれを行う)、両方のプロセスグループは同じセッションの 一部でなければならない .RB ( setsid (2) と .BR credentials (7) 参照)。この場合は \fIpgid\fP は参加すべき既存の プロセスグループを指定し、そのセッション ID は参加するプロセスの セッション ID に一致しなければならない。 .\"O The POSIX.1 version of .\"O .BR getpgrp (), .\"O which takes no arguments, .\"O returns the PGID of the calling process. POSIX.1 バージョンの .BR getpgrp () は引き数を一つもとらず、 呼び出し元プロセスの PGID を返す。 .\"O .BR getpgid () .\"O returns the PGID of the process specified by .\"O .IR pid . .\"O If .\"O .I pid .\"O is zero, the process ID of the calling process is used. .\"O (Retrieving the PGID of a process other than the caller is rarely .\"O necessary, and the POSIX.1 .\"O .BR getpgrp () .\"O is preferred for that task.) .BR getpgid () は .I pid で指定されたプロセスの PGID を返す。 .I pid がゼロならば、呼び出し元プロセスのプロセス ID が pid として使用される。 (呼び出し元プロセス以外のプロセスの PGID の取得が必要になることは めったになく、呼び出し元プロセスの PGID を取得するには POSIX.1 バージョンの .BR getpgrp () を使うのが望ましい。) .\"O The System V-style .\"O .BR setpgrp (), .\"O which takes no arguments, is equivalent to .\"O .IR "setpgid(0,\ 0)" . System V バージョンの .BR setpgrp () は引き数を一つもとらず、 .I "setpgid(0,\ 0)" と等価である。 .\"O The BSD-specific .\"O .BR setpgrp () .\"O call, which takes arguments .\"O .I pid .\"O and .\"O .IR pgid , .\"O is equivalent to .\"O .IR "setpgid(pid, pgid)" . BSD 仕様の .BR setpgrp () は .I pid と .I pgid を引き数にとり、 .I "setpgid(pid, pgid)" と等価である。 .\" The true BSD setpgrp() system call differs in allowing the PGID .\" to be set to arbitrary values, rather than being restricted to .\" PGIDs in the same session. .\"O The BSD-specific .\"O .BR getpgrp () .\"O call, which takes a single .\"O .I pid .\"O argument, is equivalent to .\"O .IR "getpgid(pid)" . BSD 仕様の .BR getpgrp () は .I pid だけを引き数にとり、 .I "getpgid(pid)" と等価である。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, .\"O .BR setpgid () .\"O and .\"O .BR setpgrp () .\"O return zero. .\"O On error, \-1 is returned, and .\"O .I errno .\"O is set appropriately. .BR setpgid () と .BR setpgrp () は成功した場合、ゼロを返す。エラーの場合は \-1 を返し、 .I errno が適切に設定される。 .\"O The POSIX.1 .\"O .BR getpgrp () .\"O always returns the PGID of the caller. POSIX.1 バージョンの .BR getpgrp () は常に呼び出しプロセスの PGID を返す。 .\"O .BR getpgid (), .\"O and the BSD-specific .\"O .BR getpgrp () .\"O return a process group on success. .\"O On error, \-1 is returned, and .\"O .I errno .\"O is set appropriately. .BR getpgid () と BSD 仕様の .BR getpgrp () は成功した場合プロセスグループを返す。 エラーの場合は \-1 を返し、 .I errno が適切に設定される。 .\"O .SH ERRORS .SH エラー .TP .B EACCES .\"O An attempt was made to change the process group ID .\"O of one of the children of the calling process and the child had .\"O already performed an .\"O .BR execve (2) .\"O .RB ( setpgid (), .\"O .BR setpgrp ()). 呼び出し元プロセスの子プロセスのプロセスグループ ID を変更しようとしたが、 すでにその子プロセスは .BR execve (2) を実行していた。 .RB ( setpgid (), .BR setpgrp ()) .TP .B EINVAL .\"O .I pgid .\"O is less than 0 .\"O .RB ( setpgid (), .\"O .BR setpgrp ()). .I pgid が 0 より小さい。 .RB ( setpgid (), .BR setpgrp ()) .TP .B EPERM .\"O An attempt was made to move a process into a process group in a .\"O different session, or to change the process .\"O group ID of one of the children of the calling process and the .\"O child was in a different session, or to change the process group ID of .\"O a session leader .\"O .RB ( setpgid (), .\"O .BR setpgrp ()). プロセスを異なるセッションのプロセスグループに移動させようとした。 または呼び出し元プロセスの子プロセスのプロセスグループ ID を変更しようと したが、その子プロセスは別のセッションだった。 またはセッションリーダーのプロセスグループ ID を変更しようとした。 .RB ( setpgid (), .BR setpgrp ()) .TP .B ESRCH .\"O For .\"O .BR getpgid (): .BR getpgid () の場合: .I pid がどのプロセスにも一致しない。 .\"O For .\"O .BR setpgid (): .\"O .I pid .\"O is not the calling process and not a child of the calling process. .BR setpgid () の場合: .I pid が呼び出し元のプロセスではなく、呼び出し元のプロセスの子プロセスでもない。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O .BR setpgid () .\"O and the version of .\"O .BR getpgrp () .\"O with no arguments .\"O conform to POSIX.1-2001. .BR setpgid () と、引き数なしバージョンの .BR getpgrp () は POSIX.1-2001 に準拠している。 .\"O POSIX.1-2001 also specifies .\"O .BR getpgid () .\"O and the version of .\"O .BR setpgrp () .\"O that takes no arguments. POSIX.1-2001 は、 .BR getpgid () と、引き数なしバージョンの .BR setpgrp () も規定している。 .\"O (POSIX.1-2008 marks this .\"O .BR setpgrp () .\"O specification as obsolete.) POSIX.1-2008 は、この .BR setpgrp () の仕様を廃止予定としている。 .\"O The version of .\"O .BR getpgrp () .\"O with one argument and the version of .\"O .BR setpgrp () .\"O that takes two arguments derive from 4.2BSD, .\"O and are not specified by POSIX.1. 引き数 1 個バージョンの .BR getpgrp () と引き数 2 個バージョンの .BR setpgrp () は 4.2BSD に由来し、 POSIX.1 では規定されていない。 .\"O .SH NOTES .SH 注意 .\"O A child created via .\"O .BR fork (2) .\"O inherits its parent's process group ID. .\"O The PGID is preserved across an .\"O .BR execve (2). .BR fork (2) で作成された子プロセスは、親プロセスの PGID を継承する。 .BR execve (2) の前後で PGID は保存される。 .\"O Each process group is a member of a session and each process is a .\"O member of the session of which its process group is a member. 各プロセスグループはセッションのメンバーであり、各プロセスは そのプロセスグループが所属しているセッションのメンバーである。 .\"O A session can have a controlling terminal. .\"O At any time, one (and only one) of the process groups .\"O in the session can be the foreground process group .\"O for the terminal; .\"O the remaining process groups are in the background. .\"O If a signal is generated from the terminal (e.g., typing the .\"O interrupt key to generate .\"O .BR SIGINT ), .\"O that signal is sent to the foreground process group. .\"O (See .\"O .BR termios (3) .\"O for a description of the characters that generate signals.) セッションは制御端末 (controlling terminal) を持つことができる。 いつでも、セッションに所属するプロセスグループの一つ (だけ) が 端末のフォアグランドのプロセスグループになることができ、 残りのプロセスグループはバックグラウンドになる。 端末からシグナルが生成された場合 (例えば、中断キーを叩いて .B SIGINT が生成されるなど)、そのシグナルはフォアグラウンドのプロセスグループ に送られる (シグナルを生成する文字の説明は .BR termios (3) を参照)。 .\"O Only the foreground process group may .\"O .BR read (2) .\"O from the terminal; .\"O if a background process group tries to .\"O .BR read (2) .\"O from the terminal, then the group is sent a .\"O .B SIGTSTP .\"O signal, which suspends it. .\"O The .\"O .BR tcgetpgrp (3) .\"O and .\"O .BR tcsetpgrp (3) .\"O functions are used to get/set the foreground .\"O process group of the controlling terminal. フォアグラウンドのプロセスグループだけが端末からの .BR read (2) ができる。 バックグラウンドのプロセスグループが端末からの .BR read (2) を行おうとした場合、そのプロセスグループにはシグナル .B SIGTSTP が送られ、そのプロセスグループは一時停止 (suspend) する。 関数 .BR tcgetpgrp (3) と .BR tcsetpgrp (3) を使うと、制御端末のフォアグラウンドのプロセスグループを 取得/設定できる。 .\"O The .\"O .BR setpgid () .\"O and .\"O .BR getpgrp () .\"O calls are used by programs such as .\"O .BR bash (1) .\"O to create process groups in order to implement shell job control. .BR setpgid () と .BR getpgrp () は、 .BR bash (1) のようなプログラムで、シェルのジョブ制御 (job control) の実装のための プロセスグループを作成するのに使われる。 .\"O If a session has a controlling terminal, and the .\"O .B CLOCAL .\"O flag for that terminal is not set, .\"O and a terminal hangup occurs, then the session leader is sent a .\"O .BR SIGHUP . .\"O If the session leader exits, then a .\"O .B SIGHUP .\"O signal will also be sent to each process in the foreground .\"O process group of the controlling terminal. セッションが制御端末を持っていて、その端末に対して .B CLOCAL フラグが設定されておらず、端末のハングアップが起きた場合、 セッション・リーダーに .B SIGHUP が送られる。 セッション・リーダーが終了した場合には、その制御端末の フォアグランドのプロセスグループに所属する各プロセスにも .B SIGHUP シグナルが送られる。 .\"O If the exit of the process causes a process group to become orphaned, .\"O and if any member of the newly orphaned process group is stopped, then a .\"O .B SIGHUP .\"O signal followed by a .\"O .B SIGCONT .\"O signal will be sent to each process .\"O in the newly orphaned process group. プロセスの終了によってプロセスグループが孤児 (orphaned) になった際に、 その新たに孤児になったプロセスグループに停止しているメンバーがいれば、 その孤児になったプロセスグループに属す全てのプロセスに .B SIGHUP シグナルに続けて .B SIGCONT シグナルが送られる。 .\" exit.3 refers to the following text: .\"O An orphaned process group is one in which the parent of .\"O every member of process group is either itself also a member .\"O of the process group or is a member of a process group .\"O in a different session (see also .\"O .BR credentials (7)). 孤児になった (orphaned) プロセスグループとは、 そのプロセスグループの全てのメンバーについて、メンバーの親プロセスが、 親プロセス自身もそのプロセスグループのメンバーか、 別のセッションに属すプロセスグループのメンバーのいずれかであるような、 プロセスグループのことである。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR getuid (2), .BR setsid (2), .BR tcgetpgrp (3), .BR tcsetpgrp (3), .BR termios (3), .BR credentials (7)