gtpc2m6bC/C++ Language Support User's Guide

setegid-Set the Effective Group ID

This function sets the effective group ID (GID) of the calling function's process to gid.

Format

#include <unistd.h>
int setegid(uid_t gid);

gid
The GID numeric value used in setting the effective GID.

Normal Return

If successful, the setegid function returns an integer value of 0.

Error Return

If unsuccessful, the setegid function returns -1 and sets errno to one of the following:

EINVAL
The value specified for gid is incorrect.

EPERM
The process does not have the appropriate privileges or gid does not match the real GID or the saved set GID.

Programming Considerations

This function sets the effective GID of the calling function's process to gid if gid is equal to the real GID or saved set GID of the calling process, or if the process has appropriate privileges.

The appropriate privileges are if the calling program has the key 0 option set on in the PAT or having the effective UID 0 (root). Otherwise, the real GID and the saved set GID are not changed.

Examples

The following example provides information for the effective group ID (GID) of the caller and sets its effective GID:

#include <unistd.h>
#include <stdio.h>
 
int main(void) {
 
  printf("Your effective group id is %d\n", (int) getegid() );
  if ( setegid ( 100 ) != 0 )
      perror ( "setegid() error" );
  else
       printf("Your effective group id was changed to %d\n",
                              (int) setegid() );
  return 0;
}

Related Information