What is os.geteuid() in Unix using Python?
The os.geteuid() method is used to extract the effective user ID of the current process. The inverse method of this function is seteuid(), which is used to set the effective user ID. These methods are commonly found on
Note: The
OSmodule in Python is used to deal with operating system commands.
Question
Effective user ID
Show Answer
Syntax
os.geteuid()
Parameters
N/A: It does not take any argument value(s).
Return value
This method returns an effective user ID as an integer type.
Code example
Now, let’s see an example of this method.
# Program to show working of geteuid() method# importing mobulesimport osimport random# generating random number between 10-100euid = random.randint(10,100)# Assigning effective user id to current threados.seteuid(euid)# Extracting id to test this methodeuid= os.geteuid()# printing euid on consoleprint(euid)
Code explanation
- Line 6: We generate a random number between 10 and 100, to use an an effective user ID.
- Line 8: We assign an effective user ID to the current process.
- Line 10: We get the effective user ID of that process, by using the
os.geteuid()method. - Line 12: We print the
to the console.euid Effective user ID