Open In App

Python | os.getresgid() and os.setresgid() method

Last Updated : 27 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

All functions in os module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system.

os.getresgid() method in Python is used to get the current process’s real, effective, and saved group ids and os.setresgid() method is used to set the current process’s real, effective, and saved group ids.

Alternatively, we can also get real and effective group ids of the current process using os.getgid() and os.getegid() method respectively and can also set the real and effective group ids of the current process using os.setgid() and os.setegid() method respectively.

Note: os.setresgid() and os.getresgid() methods are only available on UNIX platforms and functionality of os.setresgid() method is typically available only to the superuser as only superuser can change group IDs of a process. Superuser means a root user or an administrative user who has all the permissions to run or execute any program in the operating system.

os.getresgid() method –

Syntax: os.getresgid()

Parameter: No parameter is required

Return Type: This method returns a tuple whose attributes denotes real, effective, and saved group ids of the current process.

Code #1: Use of os.getresgid() method




# Python program to explain os.getresgid() method 
  
# importing os module 
import os
  
# Get the current process’s 
# real, effective, and saved group ids.
# using os.getresgid() method
rgid, egid, sgid = os.getresgid()
  
# Print the current process’s
# real, effective, and saved group ids.
print("Real group id of the current process:", rgid)
print("Effective group id of the current process:", egid)
print("Saved group id of the current process:", sgid)


Output:
os.getresgid() method output

os.setresgid() method –

Syntax: os.setresgid(rgid, egid, sgid)

Parameters:
rgid: An integer value representing new group id for the current process.
egid: An integer value representing new effective group id for the current process.
sgid: An integer value representing new saved group id for the current process.

Return Type: This method does not return any value.

Code #2: Use of os.setresgid() method




# Python program to explain os.setresgid() method 
  
# importing os module 
import os
  
  
# Get the current process’s 
# real, effective, and saved group ids
# using os.getresgid() method
rgid, egid, sgid = os.getresgid()
  
# Print the current process’s
# real, effective, and saved group ids
print("Real group id of the current process:", rgid)
print("Effective group id of the current process:", egid)
print("Saved group id of the current process:", sgid)
  
# Change the current process’s
# real, effective, and saved group ids
# using os.setresgid() method
rgid = 100
egid = 200
sgid = 300
os.setresgid(rgid, egid, sgid)
print("\nReal, effective, and saved group ids changed\n")
  
  
# Get the current process’s 
# real, effective, and saved group ids
# using os.getresgid() method
rgid, egid, sgid = os.getresgid()
  
# Print the current process’s
# real, effective, and saved group ids
print("Real group id of the current process:", rgid)
print("Effective group id of the current process:", egid)
print("Saved group id of the current process:", sgid)


Output:
os.setresgid() method output



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads