1 .\" Copyright (c) 1983, 1991 Regents of the University of California.
2 .\" and Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" @(#)getpgrp.2 6.4 (Berkeley) 3/10/91
35 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
36 .\" Modified 1995-04-15 by Michael Chastain <mec@shell.portal.com>:
38 .\" Modified 1996-07-21 by Andries Brouwer <aeb@cwi.nl>
39 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
40 .\" Modified 1999-09-02 by Michael Haardt <michael@moria.de>
41 .\" Modified 2002-01-18 by Michael Kerrisk <mtk.manpages@gmail.com>
42 .\" Modified 2003-01-20 by Andries Brouwer <aeb@cwi.nl>
43 .\" 2007-07-25, mtk, fairly substantial rewrites and rearrangements
46 .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
47 .\" all rights reserved.
48 .\" Translated Sun Nov 21 18:54:10 JST 1999
49 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
50 .\" Updated Fri Feb 7 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
51 .\" Updated Sun Feb 23 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
52 .\" Updated 2007-09-25, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.64
53 .\" Updated 2010-04-23, Akihiro MOTOKI, LDP v3.24
55 .\"WORD: process group プロセスグループ
56 .\"WORD: process group ID プロセスグループ ID
58 .\"WORD: foreground フォアグランド
59 .\"WORD: block 中断(block)
60 .\"WORD: job control ジョブ・コントロール
62 .TH SETPGID 2 2010-09-26 "Linux" "Linux Programmer's Manual"
65 .\"O setpgid, getpgid, setpgrp, getpgrp \- set/get process group
66 setpgid, getpgid, setpgrp, getpgrp \- プロセスグループの設定/取得を行う
69 .B #include <unistd.h>
71 .BI "int setpgid(pid_t " pid ", pid_t " pgid );
73 .BI "pid_t getpgid(pid_t " pid );
75 .BR "pid_t getpgrp(void);" " /* POSIX.1 version */"
77 .BI "pid_t getpgrp(pid_t " pid ");\ \ \ \ \ \ \ \ \ \ \ "
80 .BR "int setpgrp(void);" " /* System V version */"
82 .BI "int setpgrp(pid_t " pid ", pid_t " pgid ");\ "
86 .\"O Feature Test Macro Requirements for glibc (see
87 .\"O .BR feature_test_macros (7)):
89 .RB ( feature_test_macros (7)
97 _XOPEN_SOURCE\ >=\ 500 ||
98 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
100 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
101 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
104 .BR setpgrp "() (POSIX.1):"
106 _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
107 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
110 .BR setpgrp "()\ (BSD),"
111 .BR getpgrp "()\ (BSD):"
114 !\ (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE ||
115 _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE)
121 .\"O All of these interfaces are available on Linux,
122 .\"O and are used for getting and setting the
123 .\"O process group ID (PGID) of a process.
124 .\"O The preferred, POSIX.1-specified ways of doing this are:
125 .\"O .BR getpgrp (void),
126 .\"O for retrieving the calling process's PGID; and
128 .\"O for setting a process's PGID.
129 これらのインタフェースすべてが Linux で利用可能で、
130 これらを使ってプロセスのプロセスグループ ID (PGID) の
132 推奨の、POSIX.1 で規定された方法では、
134 で呼び出し元プロセスの PGID を取得し、
139 .\"O sets the PGID of the process specified by
145 .\"O is zero, then the process ID of the calling process is used.
148 .\"O is zero, then the PGID of the process specified by
150 .\"O is made the same as its process ID.
158 がゼロならば、呼び出し元プロセスのプロセス ID が pid として使用される。
162 で指定されたプロセスの PGID がそのプロセスのプロセス ID と
166 .\"O is used to move a process from one process
167 .\"O group to another (as is done by some shells when creating pipelines),
168 .\"O both process groups must be part of the same session (see
171 .\"O .BR credentials (7)).
173 .\"O the \fIpgid\fP specifies an existing process group to be joined and the
174 .\"O session ID of that group must match the session ID of the joining process.
176 をプロセスをあるプロセスグループから別のグループへ
177 移動するために使用する場合は (一部のシェルはパイプラインを生成
178 する時にこれを行う)、両方のプロセスグループは同じセッションの
183 参照)。この場合は \fIpgid\fP は参加すべき既存の
184 プロセスグループを指定し、そのセッション ID は参加するプロセスの
185 セッション ID に一致しなければならない。
187 .\"O The POSIX.1 version of
189 .\"O which takes no arguments,
190 .\"O returns the PGID of the calling process.
197 .\"O returns the PGID of the process specified by
201 .\"O is zero, the process ID of the calling process is used.
202 .\"O (Retrieving the PGID of a process other than the caller is rarely
203 .\"O necessary, and the POSIX.1
205 .\"O is preferred for that task.)
209 で指定されたプロセスの PGID を返す。
211 がゼロならば、呼び出し元プロセスのプロセス ID が pid として使用される。
212 (呼び出し元プロセス以外のプロセスの PGID の取得が必要になることは
213 めったになく、呼び出し元プロセスの PGID を取得するには
218 .\"O The System V-style
220 .\"O which takes no arguments, is equivalent to
221 .\"O .IR "setpgid(0,\ 0)" .
228 .\"O The BSD-specific
230 .\"O call, which takes arguments
234 .\"O is equivalent to
235 .\"O .IR "setpgid(pid, pgid)" .
243 .I "setpgid(pid, pgid)"
245 .\" The true BSD setpgrp() system call differs in allowing the PGID
246 .\" to be set to arbitrary values, rather than being restricted to
247 .\" PGIDs in the same session.
249 .\"O The BSD-specific
251 .\"O call, which takes a single
253 .\"O argument, is equivalent to
254 .\"O .IR "getpgid(pid)" .
262 .\"O .SH "RETURN VALUE"
269 .\"O On error, \-1 is returned, and
271 .\"O is set appropriately.
275 は成功した場合、ゼロを返す。エラーの場合は \-1 を返し、
281 .\"O always returns the PGID of the caller.
284 は常に呼び出しプロセスの PGID を返す。
287 .\"O and the BSD-specific
289 .\"O return a process group on success.
290 .\"O On error, \-1 is returned, and
292 .\"O is set appropriately.
304 .\"O An attempt was made to change the process group ID
305 .\"O of one of the children of the calling process and the child had
306 .\"O already performed an
308 .\"O .RB ( setpgid (),
309 .\"O .BR setpgrp ()).
310 呼び出し元プロセスの子プロセスのプロセスグループ ID を変更しようとしたが、
320 .\"O .RB ( setpgid (),
321 .\"O .BR setpgrp ()).
328 .\"O An attempt was made to move a process into a process group in a
329 .\"O different session, or to change the process
330 .\"O group ID of one of the children of the calling process and the
331 .\"O child was in a different session, or to change the process group ID of
332 .\"O a session leader
333 .\"O .RB ( setpgid (),
334 .\"O .BR setpgrp ()).
335 プロセスを異なるセッションのプロセスグループに移動させようとした。
336 または呼び出し元プロセスの子プロセスのプロセスグループ ID を変更しようと
337 したが、その子プロセスは別のセッションだった。
338 またはセッションリーダーのプロセスグループ ID を変更しようとした。
352 .\"O is not the calling process and not a child of the calling process.
356 が呼び出し元のプロセスではなく、呼び出し元のプロセスの子プロセスでもない。
357 .\"O .SH "CONFORMING TO"
360 .\"O and the version of
362 .\"O with no arguments
363 .\"O conform to POSIX.1-2001.
367 は POSIX.1-2001 に準拠している。
369 .\"O POSIX.1-2001 also specifies
371 .\"O and the version of
373 .\"O that takes no arguments.
379 .\"O (POSIX.1-2008 marks this
381 .\"O specification as obsolete.)
388 .\"O with one argument and the version of
390 .\"O that takes two arguments derive from 4.2BSD,
391 .\"O and are not specified by POSIX.1.
400 .\"O A child created via
402 .\"O inherits its parent's process group ID.
403 .\"O The PGID is preserved across an
406 で作成された子プロセスは、親プロセスの PGID
411 .\"O Each process group is a member of a session and each process is a
412 .\"O member of the session of which its process group is a member.
413 各プロセスグループはセッションのメンバーであり、各プロセスは
414 そのプロセスグループが所属しているセッションのメンバーである。
416 .\"O A session can have a controlling terminal.
417 .\"O At any time, one (and only one) of the process groups
418 .\"O in the session can be the foreground process group
419 .\"O for the terminal;
420 .\"O the remaining process groups are in the background.
421 .\"O If a signal is generated from the terminal (e.g., typing the
422 .\"O interrupt key to generate
424 .\"O that signal is sent to the foreground process group.
427 .\"O for a description of the characters that generate signals.)
428 セッションは制御端末 (controlling terminal) を持つことができる。
429 いつでも、セッションに所属するプロセスグループの一つ (だけ) が
430 端末のフォアグランドのプロセスグループになることができ、
431 残りのプロセスグループはバックグラウンドになる。
432 端末からシグナルが生成された場合 (例えば、中断キーを叩いて
434 が生成されるなど)、そのシグナルはフォアグラウンドのプロセスグループ
439 .\"O Only the foreground process group may
441 .\"O from the terminal;
442 .\"O if a background process group tries to
444 .\"O from the terminal, then the group is sent a
446 .\"O signal, which suspends it.
448 .\"O .BR tcgetpgrp (3)
450 .\"O .BR tcsetpgrp (3)
451 .\"O functions are used to get/set the foreground
452 .\"O process group of the controlling terminal.
453 フォアグラウンドのプロセスグループだけが端末からの
456 バックグラウンドのプロセスグループが端末からの
458 を行おうとした場合、そのプロセスグループにはシグナル
460 が送られ、そのプロセスグループは一時停止 (suspend) する。
465 を使うと、制御端末のフォアグラウンドのプロセスグループを
472 .\"O calls are used by programs such as
474 .\"O to create process groups in order to implement shell job control.
480 のようなプログラムで、シェルのジョブ制御 (job control) の実装のための
483 .\"O If a session has a controlling terminal, and the
485 .\"O flag for that terminal is not set,
486 .\"O and a terminal hangup occurs, then the session leader is sent a
488 .\"O If the session leader exits, then a
490 .\"O signal will also be sent to each process in the foreground
491 .\"O process group of the controlling terminal.
492 セッションが制御端末を持っていて、その端末に対して
494 フラグが設定されておらず、端末のハングアップが起きた場合、
498 セッション・リーダーが終了した場合には、その制御端末の
499 フォアグランドのプロセスグループに所属する各プロセスにも
503 .\"O If the exit of the process causes a process group to become orphaned,
504 .\"O and if any member of the newly orphaned process group is stopped, then a
506 .\"O signal followed by a
508 .\"O signal will be sent to each process
509 .\"O in the newly orphaned process group.
510 プロセスの終了によってプロセスグループが孤児 (orphaned) になった際に、
511 その新たに孤児になったプロセスグループに停止しているメンバーがいれば、
512 その孤児になったプロセスグループに属す全てのプロセスに
517 .\" exit.3 refers to the following text:
518 .\"O An orphaned process group is one in which the parent of
519 .\"O every member of process group is either itself also a member
520 .\"O of the process group or is a member of a process group
521 .\"O in a different session (see also
522 .\"O .BR credentials (7)).
523 孤児になった (orphaned) プロセスグループとは、
524 そのプロセスグループの全てのメンバーについて、メンバーの親プロセスが、
525 親プロセス自身もそのプロセスグループのメンバーか、
526 別のセッションに属すプロセスグループのメンバーのいずれかであるような、