SETPGID(2,L) AIX Technical Reference SETPGID(2,L)
-------------------------------------------------------------------------------
setpgid, setpgrp, setsid
PURPOSE
Sets the process group or session ID of a process.
LIBRARY
Standard C Library (libc.a)
SYNTAX
#include <sys/types.h>
int setpgid (pid pgid)
pid_t pid, pgid;
int setsid ()
int setsid ()
DESCRIPTION
The setpgid system call is used to either join an existing process group or to
create a new process group. Upon successful completion, the process group ID
of the process specified by the pid parameter is set to the pgid parameter. If
the pid parameter is 0, the process group ID of the calling process is set to
pgid. If the pgid parameter is 0, the process group ID is set equal to the
process ID of the process specified by pid. Only child processes of the
calling process in the same process session are valid targets for the setpgid
call. For a session leader, the process ID value, the process group ID value,
and the session ID value of the process must always be equal. Therefore,
setpgid does not allow the process group ID of a session leader to change.
The setsid system call is used to create a new session. It may not be called
by a process which is either a session leader or a process group leader. The
calling process becomes the session leader of this new session and upon return
has no controlling terminal. The process group ID of the calling process is
set equal to its process ID. The calling process becomes the only process in
the new process group and the only process in the new session.
The setpgrp system call is provided for compatibility with UNIX System V
systems. This system call is equivalent to setsid, creating a new session and
establishing the calling process as a session leader and process group leader.
COMPATIBILITY NOTE
For compatibility with 4.3BSD systems, there is a second setpgrp routine
available in the Berkeley Compatibility Library (libbsd.a):
Processed November 7, 1990 SETPGID(2,L) 1
SETPGID(2,L) AIX Technical Reference SETPGID(2,L)
int setpgid (pid, pgid)
pid_t pid, pgid;
This routine is equivalent to setpgid(), allowing a process to either join an
existing process group or to create a new process group.
RETURN VALUE
Upon successful completion, setpgid returns a value of 0 and setsid returns the
process group ID value of the calling process. Otherwise, -1 is returned and
errno is set to indicate the error.
ERROR CONDITIONS
The setpgid system call fails if any of the following is true:
ESRCH The process specified by the pid parameter does not exist.
EINVAL The value of the pgid argument is less than 0.
EPERM The process indicated by the pid argument is a session leader.
The value of the pid argument is valid but 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 pgid argument does not match the process ID of the
process indicated by the pid argument, and there is no process with a
process group ID that matches the value of the pgid argument in the
same session as the calling process.
ESRCH The value of the pid argument does not match the process ID of the
calling process or of a child process of the calling process.
The setsid system call fails if the following is true:
EPERM The calling process is already a session or process group leader.
RELATED INFORMATION
In this book: "fork, vfork," "getpid, getpgrp, getppid."
Processed November 7, 1990 SETPGID(2,L) 2