all Python 3Linux · macOSosfunction
os.setregid
os — user/group IDs
Set both the real and effective group ids. Availability: Unix.
Syntax
os.setregid(...)
It sets the real and effective GID in one call; -1 leaves a value unchanged. Like setreuid, it affects the saved GID implicitly by system-dependent rules. Call it before changing the UID.
Examples
import os
print(os.getgid(), os.getegid()) # → ? только Unix: реальный и эффективный GID, например 1000 1000
os.setregid(-1, os.getgid()) # → ? только Unix: -1 оставляет реальный GID прежним, меняется только эффективный
os.setregid(65534, 65534) # → ? только Unix: root одним вызовом переводит процесс в группу nogroup
print(os.getgid(), os.getegid()) # → ? 65534 65534: оба GID сменились за один вызов
os.setregid(0, 0) # → PermissionError, если процесс запущен не от root
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy