What is the os.getgid() method in Python?

Overview

In Python, the os.getgid() method is used to extract the real group id of the current thread. It is also used to set the groupID of the current process.

Note: The OS module in Python provides an interface to deal with services related to the operating system.

Syntax


os.getgid()

Parameters

This method does not take any argument value.

Return Value

It returns an integer value as a groupID.

Example

# Program to generate random numbers
import random
import os
# setting random id
os.setgid(random.randint(10,100))
# getting current group process id
groupID = os.getgid()
# Printing group id
print(groupID)

Explanation

  • Line 5: We use the setgid() function to set current process groupID with a random value between 10 and 100.
  • Line 7: We extract groupID of the current value.
  • Line 9: We print the groupID of the current process.

Free Resources