#include <unistd.h>
int setregid(gid_t rgid, gid_t egid);
setregid() is used to set the real and effective group ID s of the calling process. If rgid is -1, the real GID is not changed; if egid is -1, the effective GID is not changed. The real and effective GID s may be set to different values in the same call.
If the effective user ID of the calling process is super-user, the real GID and the effective GID can be set to any legal value.
If the effective user ID of the calling process is not super-user, either the real GID can be set to the saved setGID from execve(2) , or the effective GID can either be set to the saved setGID or the real GID . Note: if a setGID process sets its effective GID to its real GID , it can still set its effective GID back to the saved setGID .
In either case, if the real GID is being changed (that is, if rgid is not -1), or the effective GID is being changed to a value not equal to the real GID , the saved setGID is set equal to the new effective GID .
setregid() returns:
setregid() will fail and neither of the group ID s will be changed if: