getuid() — Get the real user ID
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
Format
#define _POSIX_SOURCE
#include <unistd.h>
uid_t getuid(void);
General description
Finds the real user ID (UID) of the calling process.
Returned value
getuid() returns the found value. It is always successful.
There are no documented errno values.
Example
CELEBG20
/* CELEBG20
This example provides information for your user ID.
*/
#define _POSIX_SOURCE
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
main() {
struct passwd *p;
uid_t uid;
if ((p = getpwuid(uid = getuid())) == NULL)
perror("getpwuid() error");
else {
puts("getpwuid() returned the following info for your userid:");
printf(" pw_name : %s\n", p->pw_name);
printf(" pw_uid : %d\n", (int) p->pw_uid);
printf(" pw_gid : %d\n", (int) p->pw_gid);
printf(" pw_dir : %s\n", p->pw_dir);
printf(" pw_shell : %s\n", p->pw_shell);
}
}
Output
pw_name : MVSUSR1
pw_uid : 25
pw_gid : 500
pw_dir : /u/mvsusr1
pw_shell : /bin/sh