In Python, check if executed as root

Viewed 575

How can I check if my program is running with root permission. Does Pathlib offer the possibility to query the USER-ID under Linux

1 Answers

you can access username with standard library package getpass

import getpass
print(getpass.getuser())

when code is executed with sudo or as root, user is root

Related