syscalls

getuid() — Linux system interface

Return the real user ID of the caller. geteuid returns the effective user ID, which is relevant to many authorization decisions; Linux filesystem credentials, supplementary groups, capabilities, namespaces and access policies also matter. An ID is not a username; use an appropriate account lookup when needed. Neither getuid nor geteuid signals an error through errno. The example reads identities without changing them. Compile the complete C example in a fresh private working directory using gcc -std=c17 -Wall -Wextra -Wpedantic -Werror example.c -o example; run ./example. POSIX interface; tested on Linux/glibc only. These are libc-facing signatures, not raw architecture-specific syscall ABIs.

Formal Syntax & Structure

linux syntaxlinux
#include <unistd.h>uid_t getuid(void);

Return Value

uid_t

Real user ID; always succeeds.

Working Example

Example Snippetlinux
#define _DEFAULT_SOURCE#define _POSIX_C_SOURCE 200809L#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <inttypes.h>
/* A failed check ends this short-lived demonstration. */#define CHECK(x) do { if (!(x)) { \    fprintf(stderr, "check failed at line %d: %s\n", __LINE__, #x); \    return EXIT_FAILURE; \} } while (0)
int main(void){    uid_t real = getuid(), effective = geteuid();    printf("real=%ju effective=%ju\n", (uintmax_t)real, (uintmax_t)effective);    return EXIT_SUCCESS;}
Linux Reference