Briefly compare the setgid of function and setregid of function in C language

  • 2020-04-02 03:19:51
  • OfStack

C setgid() function: sets the real group id
The header file:


#include <unistd.h>

Definition function:


int setgid(gid_t gid);

Setgid () is used to set the real group id(real gid) of the current process to the parameter gid value.

Return value: 0 on success, -1 on failure, error code in errno.

Error code:
EPERM: not called as the superuser, and the parameter gid is not one of the effective gid or saved gid values of the process.

The C setregid() function: sets the real and valid group id
The header file:


#include <unistd.h>

Definition function:


int setregid(gid_t rgid, gid_t egid);

Setregid () is used to set the parameter rgid to the actual group id of the current process, and the parameter egid to the valid group id of the current process.

Return value: 0 on success, -1 on failure, error code in errno.


Related articles: