setpgid(2)setpgid(2)NAME
setpgid, setpgrp - Set the process group ID
SYNOPSIS
#include <unistd.h>
int setpgid(
pid_t process_id,
pid_t process_group_id,
); pid_t setpgrp(
void );
Application developers may want to specify an #include statement for
<sys/types.h> before the one for <unistd.h> if programs are being
developed for multiple platforms. The additional #include statement is
not required on Tru64 UNIX systems or by ISO or XSH specifications, but
may be required on other vendors' systems that conform to these stan‐
dards.
The following alternate declaration for setpgrp() does not conform to
current standards and is supported only for backward compatibility:
int setpgrp(
pid_t process_id,
pid_t process_group_id );
STANDARDS
Interfaces documented on this reference page conform to industry stan‐
dards as follows:
setpgid(): XSH4.0, XSH4.2, XSH5.0
setpgrp(): SVID 3, XSH4.2, XSH5.0
Refer to the standards(5) reference page for more information about
industry standards and associated tags.
PARAMETERS
Specifies the ID of the process whose process group ID is to be
changed. Specifies the new process group ID.
DESCRIPTION
Use the setpgid() function to add a process to an existing process
group or to create a new process group within a process's session. The
setpgid() function does not change the process group ID of a session
leader.
The setpgid() function sets the process group ID of the process identi‐
fied by the process_id parameter. The process group ID is set to the
value specified in the process_group_id parameter.
If the process_id parameter contains 0 (zero), the setpgid() function
sets the process group ID of the calling process. The new value of the
process group ID is the one specified in the process_group_id parame‐
ter.
If the process_group_id parameter contains 0 (zero), the setpgid()
function sets the process group ID of the specified process using the
process group ID of the calling process. The specified process is the
one identified by the process_id parameter.
The setpgid() function supports job control.
The setpgrp() function sets the process group ID of the calling process
to be equal to the process ID of the calling process. If the function
creates a new session, the new session has no controlling terminal.
This function does not change the process group ID of a session leader.
NOTES
[Tru64 UNIX] When compiled in compilation environments that adhere to
Revision 4.2 or higher revisions of the XSH standard, calls to the
setpgrp() function are internally renamed by prepending _E to the func‐
tion name. When you are debugging a module that includes the setpgrp()
function prototype as defined in the _XOPEN_SOURCE_EXTENDED compilation
environment, use _Esetpgrp to refer to the setpgrp() call. See stan‐
dards(5) for further information.
[Tru64 UNIX] The backward-compatible version of the setpgrp() function
is supported for use outside of the System V habitat or compilation
environments that adhere to the XSH standard. This version of setpgrp()
is similar to the setpgid() function in that you must specify the
process ID and process group ID as parameters in the call and errors
can be returned on these values. Like its industry-standard counter‐
part, the backward-compatible version of setpgrp() does not change the
process group ID of a session leader.
RETURN VALUES
Upon successful completion, the setpgid() function returns a value of 0
(zero). Otherwise, the function returns a value of -1 and sets errno to
indicate the error.
Upon successful completion, the setpgrp() function returns the new
process group ID.
[Tru64 UNIX] The backward-compatible version of setpgrp() returns a
value of 0 (zero) on successful completion. Otherwise, the function
returns a value of -1 and sets errno to indicate the error.
ERRORS
The setpgid() function sets errno to the specified values for the fol‐
lowing conditions: The value of the process_id parameter matches the
process ID of a child process of the calling process and the child
process has successfully executed one of the exec functions. The value
of the process_group_id parameter is less than or equal to 0 (zero), or
is not a valid process ID. The process indicated by the process_id
parameter is a session leader.
The value of the process_id parameter matches the process ID of
a child process of the calling process and the child process is
not in the same session as the calling process.
The value of the process_group_id parameter is valid but does
not match the process ID of the process indicated by the
process_id parameter, and there is no process with a process
group ID that matches the value of the process_group_id parame‐
ter in the same session as the calling process. The value of
the process_id parameter does not match the process ID of the
calling process or of a child process of the calling process.
No errors are defined for the industry-standard version of the setp‐
grp() function.
[Tru64 UNIX] The backward-compatible version of setpgrp() sets errno
to the same values as setpgid().
SEE ALSO
Functions: exec(2), fork(2), getpid(2), getsid(2), kill(2)
Standards: standards(5)
Programmer's Guide
setpgid(2)