Setting Group ID

Group ID values can be altered according to the same rules as user ID values. For completeness, these functions are shown in the following sections.

The functions setgid(2) and setegid(2) establish the new real and effective group ID values, respectively. The function synopsis is as follows:

#include <sys/types.h>
#include <unistd.h>

int setgid(gid_t gid);

int setegid(gid_t egid);

These functions return 0 when successful. Otherwise, -1 is returned, and an error code is available in errno.

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.