Python: Find the parent’s process id, real user ID of the current process and change real user ID
Python Operating System Services: Exercise-8 with Solution
Write a Python program to find the parent's process ID, real user ID of the current process and change the real user ID.
Sample Solution:
Python Code :
import os
print("Parent’s process id:",os.getppid())
uid = os.getuid()
print("\nUser ID of the current process:", uid)
uid = 1400
os.setuid(uid)
print("\nUser ID changed")
print("User ID of the current process:", os.getuid())
Sample Output:
Parent’s process id: 11069 User ID of the current process: 1000 Traceback (most recent call last): File "/tmp/sessions/caaafe2b92f1fb7d/main.py", line 6, inos.setuid(uid) PermissionError: [Errno 1] Operation not permitted
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to create a file and write some text and rename the file name.
Next: Write a Python program to retrieve the current working directory and change the dir (moving up one).
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://w3resource.com/python-exercises/os/python-os-exercise-8.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics