The getuid(2) and geteuid(2) Functions

When the id(1) command runs, it needs to find out what user and group it is running under. This is accomplished by the getuid(2) and geteuid(2) functions. The function synopsis is as follows:

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

uid_t getuid(void);

uid_t geteuid(void);

The getuid(2) function returns the real uid number it is operating under, while geteuid(2) returns the effective uid. There are no errors returned; these functions always succeed.

The geteuid(2) function returns the effective uid that is currently in force. UNIX processes can arrange to become other uid values temporarily through functions such as setuid(2). For security reasons, setuid(2) functionality is severely restricted. The ...

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.