[Previous]
[Contents]
[Next]

setgid()

set the real, effective and saved group IDs

Synopsis:

#include <unistd.h>
int setgid( gid_t gid );

Description:

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.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EINVAL
The value of gid is invalid.
EPERM
The process doesn't have appropriate privileges, and gid doesn't match the real group ID.

Examples:

#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 );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, setegid(), seteuid(), setuid()


[Previous]
[Contents]
[Next]