Python | os.getsid() method
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.getsid() method in Python is used to get the session id of the process associated with the specified process id.
Note: os.getsid() method is only available on UNIX platforms.
Syntax: os.getsid(pid)
Parameter:
pid: An integer value representing the process id of the process whose session id is required.Return Type: This method returns an integer value which represents the session id of process associated with the specified process id.
# Python program to explain os.getsid() method # importing os module import os # Get the session id # of the current process # using os.getsid() method # 0 as pid represents the # calling process pid = 0 sid = os.getsid(pid) # Print the session id # of the current process print("Session id of the current process:", sid) pid = 10# Get the session id # of the process associated with # the specified pid # using os.getsid() method sid = os.getsid(pid) # Print the session id print("Session id of the process whose process id is % d:" % pid, sid) |
Output:

Recommended Posts:
- class method vs static method in Python
- Python | next() method
- Python | os.dup() method
- Python | set() method
- Python PIL | ImagePalette() Method
- Python | Tensorflow exp() method
- Python | Tensorflow log() method
- Python | os.tcgetpgrp() method
- Python | sympy.det() method
- Python | iter() method
- Python | setattr() method
- Python | Tensorflow abs() method
- Python PIL | GaussianBlur() method
- Python | os.getpgid() method
- Python | os.readlink() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



