gtpc2m6e | C/C++ Language Support User's Guide |
This function sets one or more of the group IDs (GIDs) for the current process to a specified value.
Format
#include <unistd.h> int setgid(uid_t gid);
Normal Return
If successful, the setgid function returns an integer value of 0 and the group ID is set.
Error Return
If unsuccessful, the setgid function returns -1 and sets errno to one of the following:
Programming Considerations
The appropriate privileges are when the calling program has the key 0 option set on in the PAT or when the effective UID is equal to superuser.
Examples
The following example changes the effective group ID.
#include <unistd.h> #include <stdio.h> int main(void) { printf("Your group id is %d\n", (int) getgid() ); if ( setgid ( 100 ) != 0 ) perror ( "setgid() error" ); else printf("Your group id was changed to %d\n", (int) getgid() ); return 0; }
Related Information