What is os.getegid() in UNIX using Python?
Overview
The getegid() method is used to extract the current process effective group id. The group id or unique identifier is an integer value assigned to a group of processes in a program.
Note: OS module provides an interface to interact with the operating system. This method is only available for
platforms. UNIX First released multitasking operating system
Syntax
os.getegid()
Parameters
N/A: It does not take any argument value.
Return value
It returns the effective group id of this process. Group id or unique identifier is always an integer value.
Example 1
Let’s discuss some examples of getegid() method:
# Demo code to explain getegid() method# importing os moduleimport os# Fetching group id of current processegid = os.getegid()# Show group id on consoleprint("Effective group id of this process:", egid)
Explanation
- Line 3: We import OS module in our program.
- Line 5: We fetch the current effective group id in
egidvariable. - Line 7: We print the group id of the current process on the console.
Example 2
# Demo code to explain getegid() method# by using setegid() method# importing os moduleimport os# Fetching group id of current processID = os.getegid()# Show group id on consoleprint("Before: Effective group id of this process:", ID)# Now, let's set on our choiceeffectiveID = 404os.setegid(effectiveID)print("Updated Group id: ")# Show updated group id on consoleeffectiveID = os.getegid()print("After: Fetched effective group id:", effectiveID)
Explanation
- Lines 4 to 8: We import the OS module and print the default effective group id on the console.
- Line 10: We set a demo group-id
404to a variable namedeffectiveID. - Line 11: We call
setegid()method to set effective group id. - Lines 14 to 15: We fetch and print the current process group id.