Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX1_SOURCE 2
#include <unistd.h>
int setgid(gid_t gid);
Sets one or more of the group IDs (GIDs) for the current process to gid.
If gid is the same as the process's real GID or the saved set-group-ID, setgid() always succeeds and sets the effective GID to gid.
If gid is not the same as the process's real GID, setgid() succeeds only if the process has appropriate privileges. If the process has such privileges, setgid() sets the real GID, the effective GID, and saved set GID to gid.
setgid() does not change any supplementary GIDs of the calling process.
If successful, setgid() returns 0.
⁄* CELEBS06
This example sets your GID.
*⁄
#define _POSIX_SOURCE 1
#include <unistd.h>
#include <stdio.h>
main() {
printf("your group id is %d\n", (int) getgid());
if (setgid(500) != 0)
perror("setgid() error");
else
printf("your group id was changed to %d\n",
(int) getgid());
}
your group id is 512
your group id was changed to 500