DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

setpgid(S)


setpgid -- set process group ID for job control

Syntax

cc . . . -lc

#include  <sys/types.h>

int setpgid (pid, pgid) pid_t pid, pgid;

Description

If the constant POSIX_JOB_CONTROL is defined, the setpgid routine is used to either join an existing process group or create a new process group within the session of the calling process. The process group ID of a session leader does not change. Upon successful completion, processes with a process ID that match the argument pid have their process group IDs set to the argument pgid. As a special case, if pid is zero, the process ID of the calling process is used. Also, if pgid is zero, the process ID of the indicated process is used.

If POSIX_JOB_CONTROL is not defined, the setpgid routine may not work as described above and it may fail instead.

Return value

Upon successful completion, the setpgid routine returns a value of zero. If the routine fails, a value of -1 is returned and errno is set to indicate the appropriate error.

Diagnostics

If one of the following conditions occurs, the setpgid routine fails and errno is set to the corresponding value:


[EACCES]
The value of the pid argument matches the process ID of a child process of the calling process and the child process has successfully executed one of the exec(S) routines.

[EINVAL]
The value of the pgid argument is less than zero or is an unsupported value.

[ENOSYS]
The setpgid routine is not supported by this implementation.

[EPERM]
The process specified 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 but 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 nor of a child process of the calling process.

See also

exec(S), getpid(S), setsid(S)

Standards conformance

setpgid conforms with:

X/Open Portability Guide, Issue 3, 1989 ;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003