geteuid() — Get the effective user ID

Standards

Standards / Extensions C or C++ Dependencies

POSIX.1
XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _POSIX_SOURCE
#include <unistd.h>

uid_t geteuid(void);

General description

Finds the effective user ID (UID) of the calling process.

Returned value

Returns the effective user ID of the calling process. It is always successful.

There are no documented errno values.

Example

CELEBG06
⁄* CELEBG06

   This example returns information for your user ID.

 *⁄
#define _POSIX_SOURCE
#include <sys⁄types.h>
#include <pwd.h>
#include <unistd.h>

main() {
  struct passwd *p;
  uid_t  uid;

  if ((p = getpwuid(uid = geteuid())) == 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

getpwuid() returns the following information for your user ID:
pw_name  : MVSUSR1
pw_uid   : 25
pw_gid   : 500
pw_dir   : /u/mvsusr1
pw_shell : /bin/sh

Related information