Python: Find group id, user id, real group id, supplemental group ids associated with the current process
Python Basic: Exercise-104 with Solution
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:
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/python-basic-exercise-104.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics