Chapter Contents

Previous

Next
setgid

setgid



Specify Group ID

Portability: POSIX.1 conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <sys/types.h>

int setgid(gid_t groupID);


DESCRIPTION

setgid sets one or more of the group IDs of the current process. groupID is the new group ID. setgid succeeds and sets the effective group ID to the real group ID if groupID is the same as the real group ID of the process. If groupID is not the same as the real group ID of the process, setgid succeeds only if the process belongs to a superuser, in which case it sets the real group ID, effective group ID, and saved set group ID to groupID .


RETURN VALUE

setgid returns a 0 if successful and a -1 if unsuccessful.


EXAMPLE

The following example illustrates the use of setgid to set the effective group ID to the real group ID:

#include <unistd.h>
#include <stdio.h>

main()

{
   uid_t realGID, effectiveGID;

   realGID = getgid();
   effectiveGID = getegid();

   printf("Real group ID = %dn", (int) realGID);
   printf("Effective group ID = %dn", (int) effectiveGID);

   if (realGID != effectiveGID) {
      if (setgid(realGID) != 0)
         perror("setgid error");
      else
         printf("Effective group ID changed to %d.n", (int) realGID);
   }
}


RELATED FUNCTIONS

getegid , getgid , setegid , setuid


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.