Python Glossary Русский

all Python 3Linux · macOSosfunction

os.geteuid

os — user/group IDs

Return the process's effective user id. Availability: Unix.

Syntax

os.geteuid(...)

The kernel checks access rights against the effective UID. The "running as root" check is os.geteuid() == 0, not getuid. For a setuid program the effective UID equals the owner of the program file, while the real UID is whoever launched it.

Examples

import os
print(os.geteuid())  # → ? только Unix: эффективный UID процесса, например 1000
print(os.geteuid() == 0)  # → ? только Unix: True, если скрипт выполняется с правами root
print(os.geteuid() == os.getuid())  # → ? только Unix: True; False только в setuid-программах вроде sudo
print(str(os.geteuid()).isdigit())  # → ? только Unix: True — возвращается число, а не имя; имя даёт pwd.getpwuid(os.geteuid()).pw_name

See also

Open in the full glossarydocs.python.orgReport an inaccuracy