set the real, effective and saved group IDs
#include <unistd.h> int setgid( gid_t gid );
The setgid() function allows the calling process to set the real, effective and saved group IDs, based on the following:
Any supplementary group IDs of the calling process remain unchanged by this function call.
If you wish to change only the effective group ID, even if you have appropriate privileges, you should consider using the setegid() function.
#include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> void main() { gid_t ogid; ogid = getgid(); if( setgid( 2 ) == -1 ) { perror( "setgid" ); exit( EXIT_FAILURE ); } printf( "Group ID is now 2, was %d\n", ogid ); exit( EXIT_SUCCESS ); }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
errno, setegid(), seteuid(), setuid()