diff options
| author | Michael Kerrisk <mtk.manpages@gmail.com> | 2007-07-05 21:19:36 +0000 |
|---|---|---|
| committer | Michael Kerrisk <mtk.manpages@gmail.com> | 2007-07-05 21:19:36 +0000 |
| commit | 0bbb92a373cd49b9ecf35acda901b90871e0d2b7 (patch) | |
| tree | b381039d95408327a2b035303fe8fcf0dce9f64c /man2 | |
| parent | a4de892a50769029284bea6deeebcb5ad0d45dd4 (diff) | |
| download | man-pages-0bbb92a373cd49b9ecf35acda901b90871e0d2b7.tar.gz | |
Fairly substantial changes and corrections, including adding
coverage of all of the interfaces that get/set PGIDs.
Diffstat (limited to 'man2')
| -rw-r--r-- | man2/setpgid.2 | 214 |
1 files changed, 143 insertions, 71 deletions
diff --git a/man2/setpgid.2 b/man2/setpgid.2 index 3cbe2a8be5..5872b691db 100644 --- a/man2/setpgid.2 +++ b/man2/setpgid.2 @@ -39,8 +39,10 @@ .\" Modified 1999-09-02 by Michael Haardt <michael@moria.de> .\" Modified 2002-01-18 by Michael Kerrisk <mtk-manpages@gmx.net> .\" Modified 2003-01-20 by Andries Brouwer <aeb@cwi.nl> +.\" 2007-07-25, mtk, fairly substantial rewrites and rearrangements +.\" of text. .\" -.TH SETPGID 2 2003-01-20 "Linux" "Linux Programmer's Manual" +.TH SETPGID 2 2007-07-05 "Linux" "Linux Programmer's Manual" .SH NAME setpgid, getpgid, setpgrp, getpgrp \- set/get process group .SH SYNOPSIS @@ -49,13 +51,44 @@ setpgid, getpgid, setpgrp, getpgrp \- set/get process group .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 -.B int setpgrp(void); +.BI "pid_t getpgrp(psid_t " pid ");\ \ \ \ \ \ \ \ \ " +/* BSD version */ +.sp +.BR "int setpgrp(void);" " /* System V version */" .br -.B pid_t getpgrp(void); +.BI "int setpgrp(pid_t " pid ", pid_t " pgid ); +/* BSD version */ +.sp +.in -4n +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.in +.sp +.BR getpgid (): +_XOPEN_SOURCE >= 500 +.br +.BR setpgrp () +(POSIX.1): _SVID_SOURCE || _XOPEN_SOURCE >= 500 +.sp +.BR setpgrp "()\ (BSD)," +.BR getpgrp "()\ (BSD):" +_BSD_SOURCE && ! (_POSIX_SOURCE || _POSIX_C_SOURCE || +_XOPEN_SOURCE || _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE) .SH DESCRIPTION +All of these interfaces are available on Linux, +and are used for getting and setting the +process group ID (PGID) of a process. +The preferred, POSIX.1-specified ways of doing this are: +.BR getpgrp (void), +for retrieving the calling process's PGID; and +.BR setpgid (), +for setting a process's PGID. + .BR setpgid () -sets the process group ID of the process specified by +sets the PGID of the process specified by .I pid to .IR pgid . @@ -71,63 +104,53 @@ If .BR setpgid () is used to move a process from one process group to another (as is done by some shells when creating pipelines), -both process groups must be part of the same session. +both process groups must be part of the same session (see +.BR setsid (2) +and +.BR credentials (7)). In this case, the \fIpgid\fP specifies an existing process group to be joined and the session ID of that group must match the session ID of the joining process. +The POSIX.1 version of +.BR getpgrp (), +which takes no arguments, +returns the PGID of the calling process. + .BR getpgid () -returns the process group ID of the process specified by +returns the PGID of the process specified by .IR pid . If .I pid is zero, the process ID of the current process is used. +(Retrieving the PGID of a process other than the caller is rarely +necessary, and the POSIX.1 +.BR getpgrp () +is preferred for that task.) -The call -.IR setpgrp () +The System V-style +.BR setpgrp () is equivalent to .IR "setpgid(0,\ 0)" . -Similarly, -.IR getpgrp () -is equivalent to -.IR getpgid(0) . -Each process group is a member of a session and each process is a -member of the session of which its process group is a member. - -Process groups are used for distribution of signals, and by terminals to -arbitrate requests for their input: Processes that have the same process -group as the terminal are foreground and may read, while others will -block with a signal if they attempt to read. -These calls are thus used by programs such as -.BR csh (1) -to create process groups in implementing job control. -The -.B TIOCGPGRP +The BSD-specific +.BR setpgrp () +call, which takes arguments +.I pid and -.B TIOCSPGRP -calls described in -.BR termios (3) -are used to get/set the process group of the control terminal. - -If a session has a controlling terminal, -.B CLOCAL -is not set and a hangup -occurs, then the session leader is sent a -.BR SIGHUP . -If the session leader -exits, the -.B SIGHUP -signal will be sent to each process in the foreground -process group of the controlling terminal. +.IR pgid , +is equivalent to +.IR "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. -If the exit of the process causes a process group to become orphaned, -and if any member of the newly-orphaned process group is stopped, then a -.B SIGHUP -signal followed by a -.B SIGCONT -signal will be sent to each process -in the newly-orphaned process group. +The BSD-specific +.BR getpgrp () +call, which takes a single +.I pid +argument, is equivalent to +.IR "getpgid(pid)" . .SH "RETURN VALUE" On success, .BR setpgid () @@ -138,14 +161,17 @@ On error, \-1 is returned, and .I errno is set appropriately. -.BR getpgid () -returns a process group on success. +The POSIX.1 +.BR getpgrp () +always returns the current process group. + +.BR getpgid (), +and the BSD-specific +.BR getpgrp () +return a process group on success. On error, \-1 is returned, and .I errno is set appropriately. - -.BR getpgrp () -always returns the current process group. .SH ERRORS .TP .B EACCES @@ -181,17 +207,24 @@ For .I pid is not the current process and not a child of the current process. .SH "CONFORMING TO" -The functions .BR setpgid () -and +and the version of .BR getpgrp () +with no argumennts conform to POSIX.1-2001. -The function -.BR setpgrp () -is from 4.2BSD. -The function + +POSIX.1-2001 also specifies .BR getpgid () -conforms to SVr4. +and the version of +.BR setpgrp () +that takes no arguments. + +The version of +.BR getpgrp () +with one argument and the version of +.BR setpgrp () +that takes two arguments derive from 4.2BSD, +and are not specified by POSIX.1. .SH NOTES A child created via .BR fork (2) @@ -199,23 +232,62 @@ inherits its parent's process group ID. The process group ID is preserved across an .BR execve (2). -POSIX took +Each process group is a member of a session and each process is a +member of the session of which its process group is a member. + +A session can have a controlling terminal. +At any time, one (and only one) of the process groups +in the session can be the foreground process group +for the terminal; +the remaining process groups are in the background. +If a signal is generated from the terminal (e.g., typing the +interrupt key to generate +.BR SIGINT ), +that signal is sent to the foreground process group. +(See +.BR termios (3) +for a description of the characters that generate signals.) +Only the foreground process group may read from the terminal; +if a background process group tries to read from the terminal, +then the group is send a +.BR SIGTSTP +signal, which suspends it. +The +.BR tcgetpgrp (3) +and +.BR tcsetpgrp (3) +functions are used to get/set the foreground +process group of the controlling terminal. + +The .BR setpgid () -from the BSD function -.BR setpgrp (). -Also System V has a function with the same name, but it is identical to -.BR setsid (2). -.LP -To get the prototypes under glibc, define both -.B _XOPEN_SOURCE and -.BR _XOPEN_SOURCE_EXTENDED , -or use "#define _XOPEN_SOURCE \fIn\fP" -for some integer \fIn\fP larger than or equal to 500. +.BR getpgrp () +calls are used by programs such as +.BR bash (1) +to create process groups in order to implement shell job control. + +If a session has a controlling terminal, +and the +.B CLOCAL +flag for that terminal is not set, +and a terminal hangup occurs, then the session leader is sent a +.BR SIGHUP . +If the session leader exits, then a +.B SIGHUP +signal will also be sent to each process in the foreground +process group of the controlling terminal. + +If the exit of the process causes a process group to become orphaned, +and if any member of the newly orphaned process group is stopped, then a +.B SIGHUP +signal followed by a +.B SIGCONT +signal will be sent to each process +in the newly orphaned process group. .SH "SEE ALSO" .BR getuid (2), .BR setsid (2), .BR tcgetpgrp (3), .BR tcsetpgrp (3), -.BR termios (3), -.BR feature_test_macros (7) +.BR termios (3) |
