Copyright (C), 1994, Graeme W. Wilford. (Wilf.) and Copyright (C) 2010, 2015, Michael Kerrisk <firstname.lastname@example.org> %%%LICENSE_START(VERBATIM) Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed und...
NAMEsetgid - set group identity
int setgid(gid_t gid);
DESCRIPTIONsetgid() sets the effective group ID of the calling process. If the calling process is privileged (has the CAP_SETGID capability in its user namespace), the real GID and saved set-group-ID are also set.
Under Linux, setgid() is implemented like the POSIX version with the _POSIX_SAVED_IDS feature. This allows a set-group-ID program that is not set-user-ID-root to drop all of its group privileges, do some un-privileged work, and then reengage the original effective group ID in a secure manner.
RETURN VALUEOn success, zero is returned. On error, -1 is returned, and errno is set appropriately.
- The group ID specified in gid is not valid in this user namespace.
- The calling process is not privileged (does not have the CAP_SETGID capability), and gid does not match the real group ID or saved set-group-ID of the calling process.