OSDN Git Service

26c244cbcec1cba2625f33fc850f1e248a54cab2
[linuxjm/LDP_man-pages.git] / draft / man2 / setpgid.2
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.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
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.
20 .\"
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
31 .\" SUCH DAMAGE.
32 .\"
33 .\"     @(#)getpgrp.2   6.4 (Berkeley) 3/10/91
34 .\"
35 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
36 .\" Modified 1995-04-15 by Michael Chastain <mec@shell.portal.com>:
37 .\"   Added 'getpgid'.
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
44 .\" of text.
45 .\"
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
54 .\"
55 .\"WORD:        process group           プロセスグループ
56 .\"WORD:        process group ID        プロセスグループ ID
57 .\"WORD:        terminal                端末
58 .\"WORD:        foreground              フォアグランド
59 .\"WORD:        block                   中断(block)
60 .\"WORD:        job control             ジョブ・コントロール
61 .\"
62 .TH SETPGID 2 2010-09-26 "Linux" "Linux Programmer's Manual"
63 .\"O .SH NAME
64 .SH 名前
65 .\"O setpgid, getpgid, setpgrp, getpgrp \- set/get process group
66 setpgid, getpgid, setpgrp, getpgrp \- プロセスグループの設定/取得を行う
67 .\"O .SH SYNOPSIS
68 .SH 書式
69 .B #include <unistd.h>
70 .sp
71 .BI "int setpgid(pid_t " pid ", pid_t " pgid );
72 .br
73 .BI "pid_t getpgid(pid_t " pid );
74 .sp
75 .BR "pid_t getpgrp(void);" "                 /* POSIX.1 version */"
76 .br
77 .BI "pid_t getpgrp(pid_t " pid ");\ \ \ \ \ \ \ \ \ \ \ "
78 /* BSD version */
79 .sp
80 .BR "int setpgrp(void);" "                   /* System V version */"
81 .br
82 .BI "int setpgrp(pid_t " pid ", pid_t " pgid ");\ "
83 /* BSD version */
84 .sp
85 .in -4n
86 .\"O Feature Test Macro Requirements for glibc (see
87 .\"O .BR feature_test_macros (7)):
88 glibc 向けの機能検査マクロの要件
89 .RB ( feature_test_macros (7)
90 参照):
91 .in
92 .sp
93 .ad l
94 .PD 0
95 .BR getpgid ():
96 .RS 4
97 _XOPEN_SOURCE\ >=\ 500 ||
98 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
99 .br
100 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
101 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
102 .RE
103 .sp
104 .BR setpgrp "() (POSIX.1):"
105 .nf
106     _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
107     _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
108 .fi
109 .sp
110 .BR setpgrp "()\ (BSD),"
111 .BR getpgrp "()\ (BSD):"
112 .nf
113     _BSD_SOURCE &&
114         !\ (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE ||
115            _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE)
116 .fi
117 .PD
118 .ad
119 .\"O .SH DESCRIPTION
120 .SH 説明
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
127 .\"O .BR setpgid (),
128 .\"O for setting a process's PGID.
129 これらのインタフェースすべてが Linux で利用可能で、
130 これらを使ってプロセスのプロセスグループ ID (PGID) の
131 取得や設定ができる。
132 推奨の、POSIX.1 で規定された方法では、
133 .BR getpgrp (void)
134 で呼び出し元プロセスの PGID を取得し、
135 .BR setpgid ()
136 で設定する。
137
138 .\"O .BR setpgid ()
139 .\"O sets the PGID of the process specified by
140 .\"O .I pid
141 .\"O to
142 .\"O .IR pgid .
143 .\"O If
144 .\"O .I pid
145 .\"O is zero, then the process ID of the calling process is used.
146 .\"O If
147 .\"O .I pgid
148 .\"O is zero, then the PGID of the process specified by
149 .\"O .I pid
150 .\"O is made the same as its process ID.
151 .BR setpgid ()
152
153 .I pid
154 で指定したプロセスの PGID に
155 .I pgid
156 を設定する。
157 .I pid
158 がゼロならば、呼び出し元プロセスのプロセス ID が pid として使用される。
159 .I pgid
160 がゼロならば、
161 .I pid
162 で指定されたプロセスの PGID がそのプロセスのプロセス ID と
163 同じに設定される。
164 .\"O If
165 .\"O .BR setpgid ()
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
169 .\"O .BR setsid (2)
170 .\"O and
171 .\"O .BR credentials (7)).
172 .\"O In this case,
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.
175 .BR setpgid ()
176 をプロセスをあるプロセスグループから別のグループへ
177 移動するために使用する場合は (一部のシェルはパイプラインを生成
178 する時にこれを行う)、両方のプロセスグループは同じセッションの
179 一部でなければならない
180 .RB ( setsid (2)
181
182 .BR credentials (7)
183 参照)。この場合は \fIpgid\fP は参加すべき既存の
184 プロセスグループを指定し、そのセッション ID は参加するプロセスの
185 セッション ID に一致しなければならない。
186
187 .\"O The POSIX.1 version of
188 .\"O .BR getpgrp (),
189 .\"O which takes no arguments,
190 .\"O returns the PGID of the calling process.
191 POSIX.1 バージョンの
192 .BR getpgrp ()
193 は引き数を一つもとらず、
194 呼び出し元プロセスの PGID を返す。
195
196 .\"O .BR getpgid ()
197 .\"O returns the PGID of the process specified by
198 .\"O .IR pid .
199 .\"O If
200 .\"O .I pid
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
204 .\"O .BR getpgrp ()
205 .\"O is preferred for that task.)
206 .BR getpgid ()
207
208 .I pid
209 で指定されたプロセスの PGID を返す。
210 .I pid
211 がゼロならば、呼び出し元プロセスのプロセス ID が pid として使用される。
212 (呼び出し元プロセス以外のプロセスの PGID の取得が必要になることは
213 めったになく、呼び出し元プロセスの PGID を取得するには
214 POSIX.1 バージョンの
215 .BR getpgrp ()
216 を使うのが望ましい。)
217
218 .\"O The System V-style
219 .\"O .BR setpgrp (),
220 .\"O which takes no arguments, is equivalent to
221 .\"O .IR "setpgid(0,\ 0)" .
222 System V バージョンの
223 .BR setpgrp ()
224 は引き数を一つもとらず、
225 .I "setpgid(0,\ 0)"
226 と等価である。
227
228 .\"O The BSD-specific
229 .\"O .BR setpgrp ()
230 .\"O call, which takes arguments
231 .\"O .I pid
232 .\"O and
233 .\"O .IR pgid ,
234 .\"O is equivalent to
235 .\"O .IR "setpgid(pid, pgid)" .
236 BSD 仕様の
237 .BR setpgrp ()
238
239 .I pid
240
241 .I pgid
242 を引き数にとり、
243 .I "setpgid(pid, pgid)"
244 と等価である。
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.
248
249 .\"O The BSD-specific
250 .\"O .BR getpgrp ()
251 .\"O call, which takes a single
252 .\"O .I pid
253 .\"O argument, is equivalent to
254 .\"O .IR "getpgid(pid)" .
255 BSD 仕様の
256 .BR getpgrp ()
257
258 .I pid
259 だけを引き数にとり、
260 .I "getpgid(pid)"
261 と等価である。
262 .\"O .SH "RETURN VALUE"
263 .SH 返り値
264 .\"O On success,
265 .\"O .BR setpgid ()
266 .\"O and
267 .\"O .BR setpgrp ()
268 .\"O return zero.
269 .\"O On error, \-1 is returned, and
270 .\"O .I errno
271 .\"O is set appropriately.
272 .BR setpgid ()
273
274 .BR setpgrp ()
275 は成功した場合、ゼロを返す。エラーの場合は \-1 を返し、
276 .I errno
277 が適切に設定される。
278
279 .\"O The POSIX.1
280 .\"O .BR getpgrp ()
281 .\"O always returns the PGID of the caller.
282 POSIX.1 バージョンの
283 .BR getpgrp ()
284 は常に呼び出しプロセスの PGID を返す。
285
286 .\"O .BR getpgid (),
287 .\"O and the BSD-specific
288 .\"O .BR getpgrp ()
289 .\"O return a process group on success.
290 .\"O On error, \-1 is returned, and
291 .\"O .I errno
292 .\"O is set appropriately.
293 .BR getpgid ()
294 と BSD 仕様の
295 .BR getpgrp ()
296 は成功した場合プロセスグループを返す。
297 エラーの場合は \-1 を返し、
298 .I errno
299 が適切に設定される。
300 .\"O .SH ERRORS
301 .SH エラー
302 .TP
303 .B EACCES
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
307 .\"O .BR execve (2)
308 .\"O .RB ( setpgid (),
309 .\"O .BR setpgrp ()).
310 呼び出し元プロセスの子プロセスのプロセスグループ ID を変更しようとしたが、
311 すでにその子プロセスは
312 .BR execve (2)
313 を実行していた。
314 .RB ( setpgid (),
315 .BR setpgrp ())
316 .TP
317 .B EINVAL
318 .\"O .I pgid
319 .\"O is less than 0
320 .\"O .RB ( setpgid (),
321 .\"O .BR setpgrp ()).
322 .I pgid
323 が 0 より小さい。
324 .RB ( setpgid (),
325 .BR setpgrp ())
326 .TP
327 .B EPERM
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 を変更しようとした。
339 .RB ( setpgid (),
340 .BR setpgrp ())
341 .TP
342 .B ESRCH
343 .\"O For
344 .\"O .BR getpgid ():
345 .BR getpgid ()
346 の場合:
347 .I pid
348 がどのプロセスにも一致しない。
349 .\"O For
350 .\"O .BR setpgid ():
351 .\"O .I pid
352 .\"O is not the calling process and not a child of the calling process.
353 .BR setpgid ()
354 の場合:
355 .I pid
356 が呼び出し元のプロセスではなく、呼び出し元のプロセスの子プロセスでもない。
357 .\"O .SH "CONFORMING TO"
358 .SH 準拠
359 .\"O .BR setpgid ()
360 .\"O and the version of
361 .\"O .BR getpgrp ()
362 .\"O with no arguments
363 .\"O conform to POSIX.1-2001.
364 .BR setpgid ()
365 と、引き数なしバージョンの
366 .BR getpgrp ()
367 は POSIX.1-2001 に準拠している。
368
369 .\"O POSIX.1-2001 also specifies
370 .\"O .BR getpgid ()
371 .\"O and the version of
372 .\"O .BR setpgrp ()
373 .\"O that takes no arguments.
374 POSIX.1-2001 は、
375 .BR getpgid ()
376 と、引き数なしバージョンの
377 .BR setpgrp ()
378 も規定している。
379 .\"O (POSIX.1-2008 marks this
380 .\"O .BR setpgrp ()
381 .\"O specification as obsolete.)
382 POSIX.1-2008 は、この
383 .BR setpgrp ()
384 の仕様を廃止予定としている。
385
386 .\"O The version of
387 .\"O .BR getpgrp ()
388 .\"O with one argument and the version of
389 .\"O .BR setpgrp ()
390 .\"O that takes two arguments derive from 4.2BSD,
391 .\"O and are not specified by POSIX.1.
392 引き数 1 個バージョンの
393 .BR getpgrp ()
394 と引き数 2 個バージョンの
395 .BR setpgrp ()
396 は 4.2BSD に由来し、
397 POSIX.1 では規定されていない。
398 .\"O .SH NOTES
399 .SH 注意
400 .\"O A child created via
401 .\"O .BR fork (2)
402 .\"O inherits its parent's process group ID.
403 .\"O The PGID is preserved across an
404 .\"O .BR execve (2).
405 .BR fork (2)
406 で作成された子プロセスは、親プロセスの PGID
407 を継承する。
408 .BR execve (2)
409 の前後で PGID は保存される。
410
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 そのプロセスグループが所属しているセッションのメンバーである。
415
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
423 .\"O .BR SIGINT ),
424 .\"O that signal is sent to the foreground process group.
425 .\"O (See
426 .\"O .BR termios (3)
427 .\"O for a description of the characters that generate signals.)
428 セッションは制御端末 (controlling terminal) を持つことができる。
429 いつでも、セッションに所属するプロセスグループの一つ (だけ) が
430 端末のフォアグランドのプロセスグループになることができ、
431 残りのプロセスグループはバックグラウンドになる。
432 端末からシグナルが生成された場合 (例えば、中断キーを叩いて
433 .B SIGINT
434 が生成されるなど)、そのシグナルはフォアグラウンドのプロセスグループ
435 に送られる
436 (シグナルを生成する文字の説明は
437 .BR termios (3)
438 を参照)。
439 .\"O Only the foreground process group may
440 .\"O .BR read (2)
441 .\"O from the terminal;
442 .\"O if a background process group tries to
443 .\"O .BR read (2)
444 .\"O from the terminal, then the group is sent a
445 .\"O .B SIGTSTP
446 .\"O signal, which suspends it.
447 .\"O The
448 .\"O .BR tcgetpgrp (3)
449 .\"O and
450 .\"O .BR tcsetpgrp (3)
451 .\"O functions are used to get/set the foreground
452 .\"O process group of the controlling terminal.
453 フォアグラウンドのプロセスグループだけが端末からの
454 .BR read (2)
455 ができる。
456 バックグラウンドのプロセスグループが端末からの
457 .BR read (2)
458 を行おうとした場合、そのプロセスグループにはシグナル
459 .B SIGTSTP
460 が送られ、そのプロセスグループは一時停止 (suspend) する。
461 関数
462 .BR tcgetpgrp (3)
463
464 .BR tcsetpgrp (3)
465 を使うと、制御端末のフォアグラウンドのプロセスグループを
466 取得/設定できる。
467
468 .\"O The
469 .\"O .BR setpgid ()
470 .\"O and
471 .\"O .BR getpgrp ()
472 .\"O calls are used by programs such as
473 .\"O .BR bash (1)
474 .\"O to create process groups in order to implement shell job control.
475 .BR setpgid ()
476
477 .BR getpgrp ()
478 は、
479 .BR bash (1)
480 のようなプログラムで、シェルのジョブ制御 (job control) の実装のための
481 プロセスグループを作成するのに使われる。
482
483 .\"O If a session has a controlling terminal, and the
484 .\"O .B CLOCAL
485 .\"O flag for that terminal is not set,
486 .\"O and a terminal hangup occurs, then the session leader is sent a
487 .\"O .BR SIGHUP .
488 .\"O If the session leader exits, then a
489 .\"O .B SIGHUP
490 .\"O signal will also be sent to each process in the foreground
491 .\"O process group of the controlling terminal.
492 セッションが制御端末を持っていて、その端末に対して
493 .B CLOCAL
494 フラグが設定されておらず、端末のハングアップが起きた場合、
495 セッション・リーダーに
496 .B SIGHUP
497 が送られる。
498 セッション・リーダーが終了した場合には、その制御端末の
499 フォアグランドのプロセスグループに所属する各プロセスにも
500 .B SIGHUP
501 シグナルが送られる。
502
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
505 .\"O .B SIGHUP
506 .\"O signal followed by a
507 .\"O .B SIGCONT
508 .\"O signal will be sent to each process
509 .\"O in the newly orphaned process group.
510 プロセスの終了によってプロセスグループが孤児 (orphaned) になった際に、
511 その新たに孤児になったプロセスグループに停止しているメンバーがいれば、
512 その孤児になったプロセスグループに属す全てのプロセスに
513 .B SIGHUP
514 シグナルに続けて
515 .B SIGCONT
516 シグナルが送られる。
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 別のセッションに属すプロセスグループのメンバーのいずれかであるような、
527 プロセスグループのことである。
528 .\"O .SH "SEE ALSO"
529 .SH 関連項目
530 .BR getuid (2),
531 .BR setsid (2),
532 .BR tcgetpgrp (3),
533 .BR tcsetpgrp (3),
534 .BR termios (3),
535 .BR credentials (7)