Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

fork(2)

getpid(2)

getuid(2)

intro(2)

kill(2)

setpgid(2)

setsid(2)

signal(2)

termio(7)

termios(7)

getpgrp(2)

NAME

getpgrp, setpgrp, getpgid − get/set process group

SYNOPSIS (SYSV)

#include <sys/types.h>

pid_t getpgrp ()

pid_t setpgrp ()

SYNOPSIS (BSD)

#include <sys/types.h>

pid_t getpgrp (pid)
pid_t pid;

pid_t setpgrp (pid, pgrp)
pid_t pid, pgrp;

SYNOPSIS

pid_t getpgid (pid)
pid_t pid;

DESCRIPTION

These services get and set the process group ID of a process. 

In the att universe they apply to the calling process only.  getpgrp returns the process group ID of the caller.  Setpgrp sets the process group ID of the caller to his process ID and returns the new process group ID.  It also has the side effect of relinquishing the controlling terminal, creating a new session and making the calling process the session leader.  See setsid (2). 

In the ucb universe they apply to process pid, with a pid of zero refering to the caller.  getpgrp returns the process group ID of the specified process.  Setpgrp sets the process group ID of the specified process to the value in pgrp. Setpgrp adheres to the POSIX rules regarding the setting of process groups.  See setpgid (2). 

Getpgid is equivalent to the ucb universe flavor of getpgrp, but is available from either universe. 

Process groups are used for distribution of signals, and by terminals to arbitrate requests for their input: processes which 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. 

This call is thus used by programs such as csh(1) to create process groups in implementing job control.  The TIOCGPGRP and TIOCSPGRP calls described in sgtty(7) are used to get/set the process group of the control terminal, as are the TC_PX_GETPGRP and TC_PX_SETPGRP calls described in termios(7). 

RETURN VALUE

If an error occurs, the value −1 is returned, and a more precise error code is placed in the global variable errno.  If the call succeeds, then getpgrp and getpgid return the process group ID, setpgrp in the att universe returns the new process group ID, and setpgrp in the ucb universe returns 0. 

ERRORS

getpgrp and getpgid will fail if one of the following occur:

[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. 

Setpgrp will fail and the process group will not be altered if one of the following occur:

­[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() functions. 

­[EINVAL] The value of the pgid argument is less than zero or is not a value supported by the implementation. 

­[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. 

SEE ALSO

exec(2), fork(2), getpid(2), getuid(2), intro(2), kill(2), setpgid(2), setsid(2), signal(2), termio(7), termios(7). 

CX/UX Programmer’s Reference Manual

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026