Here are descriptions of the functions for manipulating process groups. Your program should include the header files `sys/types.h' and `unistd.h' to use these functions.
setsid
function creates a new session. The calling process
becomes the session leader, and is put in a new process group whose
process group ID is the same as the process ID of that process. There
are initially no other processes in the new process group, and no other
process groups in the new session.
This function also makes the calling process have no controlling terminal.
The setsid
function returns the new process group ID of the
calling process if successful. A return value of -1
indicates an
error. The following errno
error conditions are defined for this
function:
EPERM
The getsid
function returns the process group ID of the session
leader of the specified process. If a pid is 0
, the
process group ID of the session leader of the current process is
returned.
In case of error -1
is returned and errno
is set. The
following errno
error conditions are defined for this function:
ESRCH
EPERM
The getpgrp
function has two definitions: one derived from BSD
Unix, and one from the POSIX.1 standard. The feature test macros you
have selected (see section Feature Test Macros) determine which definition
you get. Specifically, you get the BSD version if you define
_BSD_SOURCE
; otherwise, you get the POSIX version if you define
_POSIX_SOURCE
or _GNU_SOURCE
. Programs written for old
BSD systems will not include `unistd.h', which defines
getpgrp
specially under _BSD_SOURCE
. You must link such
programs with the -lbsd-compat
option to get the BSD definition.
getpgrp
returns the process group ID of
the calling process.
getpgrp
returns the process group ID of the
process pid. You can supply a value of 0
for the pid
argument to get information about the calling process.
getpgid
is the same as the BSD function getpgrp
. It
returns the process group ID of the process pid. You can supply a
value of 0
for the pid argument to get information about
the calling process.
In case of error -1
is returned and errno
is set. The
following errno
error conditions are defined for this function:
ESRCH
setpgid
function puts the process pid into the process
group pgid. As a special case, either pid or pgid can
be zero to indicate the process ID of the calling process.
This function fails on a system that does not support job control. See section Job Control is Optional, for more information.
If the operation is successful, setpgid
returns zero. Otherwise
it returns -1
. The following errno
error conditions are
defined for this function:
EACCES
exec
function since it was forked.
EINVAL
ENOSYS
EPERM
ESRCH
setpgid
. Both functions do exactly
the same thing.
Go to the first, previous, next, last section, table of contents.