Python Glossary Русский

all Python 3Linux · macOSosfunction

os.setegid

os — user/group IDs

Set the process's effective group id. Availability: Unix.

Syntax

os.setegid(...)

It changes only the effective group while the saved one stays, so the change is reversible. Like seteuid, it suits temporary action on behalf of another group, not a permanent drop of privileges.

Examples

import os
saved_gid = os.getegid()  # → ? только Unix: текущий эффективный GID, например 1000
os.setegid(os.getgid())  # → ? только Unix: временно понижает права до реальной группы пользователя
print(os.getegid() == os.getgid())  # → ? True: эффективный GID совпал с реальным
os.setegid(saved_gid)  # → ? только Unix: возврат к прежнему эффективному GID
os.setegid(0)  # → PermissionError, если процесс запущен не от root

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy