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 UNIXFirst released multitasking operating system platforms.

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 module
import os
# Fetching group id of current process
egid = os.getegid()
# Show group id on console
print("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 egid variable.
  • 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 module
import os
# Fetching group id of current process
ID = os.getegid()
# Show group id on console
print("Before: Effective group id of this process:", ID)
# Now, let's set on our choice
effectiveID = 404
os.setegid(effectiveID)
print("Updated Group id: ")
# Show updated group id on console
effectiveID = 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 404 to a variable named effectiveID.
  • Line 11: We call setegid() method to set effective group id.
  • Lines 14 to 15: We fetch and print the current process group id.

Free Resources