---
name: "setrgid"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/setrgid"
---

# setrgid(3)

set user and group ID

## NAME

**setruid**, **setrgid** – set user and group ID

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<unistd.h\>**

*int*\

**setruid**(*uid\_t ruid*);

*int*\

**setrgid**(*gid\_t rgid*);

## DESCRIPTION

The **setruid**() function (**setrgid**()) sets the real user ID (group ID) of the current process.

## RETURN VALUES

The **setruid()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## COMPATIBILITY

The use of these calls is not portable. Their use is discouraged; they will be removed in the future.

## ERRORS

The functions fail if:

- \[EPERM\]

  The user is not the super user and the ID specified is not the real or effective ID.

## SEE ALSO

[getgid(2)](/getgid/2.md), [getuid(2)](/getuid/2.md), [setegid(2)](/setegid/2.md), [seteuid(2)](/seteuid/2.md), [setgid(2)](/setgid/2.md), [setuid(2)](/setuid/2.md)

## HISTORY

The **setruid**() and **setrgid**() syscalls appeared in 4.2BSD and were dropped in 4.4BSD.
