w3resource

Python: Find group id, user id, real group id, supplemental group ids associated with the current process


Process Group and User IDs

Write a Python program to get the effective group id, effective user id, real group id, and a list of supplemental group ids associated with the current process.

Note: Availability: Unix.

Sample Solution:

Python Code:

# Import the 'os' module for operating system-related functions.
import os

# Print a newline for clarity.
print()

# Get the effective group ID and print it.
print("Effective group id: ", os.getegid())

# Get the effective user ID and print it.
print("Effective user id: ", os.geteuid())

# Get the real group ID and print it.
print("Real group id: ", os.getgid())

# Get the list of supplemental group IDs and print them.
print("List of supplemental group ids: ", os.getgroups())

# Print another newline for clarity.
print()

Sample Output:

Effective group id:  1007                                          
Effective user id:  1006                                           
Real group id:  1007                                               
List of supplemental group ids:  [1007]  

Flowchart:

Flowchart: Find group id, user id, real group id, supplemental group ids associated with the current process.

For more Practice: Solve these Related Problems:

  • Write a Python program to get the user ID and group ID of a specific user.
  • Write a Python program to check if the current user has root privileges.
  • Write a Python program to get the list of all groups a user belongs to.
  • Write a Python program to get the username of the currently logged-in user.

Go to:


Previous: Write a Python program to extract the filename from a given path.
Next: Write a Python program to get the users environment.

Python Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.