Here are a couple of wrapper calls—the setresuid(2) and the setresgid(2); their signatures:
#define _GNU_SOURCE /* See feature_test_macros(7) */#include <unistd.h>int setresuid(uid_t ruid, uid_t euid, uid_t suid);int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
This pair of system calls is like a superset of the earlier set*id() APIs. With the setresuid(2) system call, a process can set the RUID, EUID, and saved-set-id all at once, with a single system call (the res in the system call name stands for real, effective, and saved-set-ID, respectively).
A non-privileged (meaning, non-root) process can only use this system call to set the three IDs to one of the current RUID, the current EUID, or the current ...