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.

Python Code Editor:

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

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.