Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

setpgid - set process group ID for job control

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

Optional
#include <sys/types.h>

int setpgid(pid_t pid, pid_t pgid); 

Description

setpgid() is used either to join an existing process group or create a new process group within the session of the calling process. If pgid is equal to pid, the process becomes a process group leader. If pgid is not equal to pid, the process becomes a member of an existing process group. The process group ID of the session leader does not change. Upon successful completion, the process group ID of the process with the process ID that matches pid is set to pgid.

If pid is 0, the process ID of the calling process is used.

If pgid is 0, the process group ID of the specified process is used.

Return val.

0

-1

if successful.

if unsuccessful. errno is set to indicate the error.

Errors

setpgid() will fail if: 

 

EACCES

The value of pid 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 pgid is less than 0 or not supported by the implementation.

 

EPERM

The process specified by pid is a session leader, or the value of pid 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, or the value of pgid is valid but does not match the process ID of the process specified by pid, and there is no process with a process group ID that matches the value of pgid in the same session as the calling process.

 

ESRCH

The value of pid does not match the process ID of the calling process or of a child process of the calling process.

See also

exec, getpgrp(), setsid(), tcsetpgrp(), sys/types.h, unistd.h.