Python | os.getsid() method
Last Updated :
27 Jun, 2019
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.
Code: Use of os.getsid() method
import os
pid = 0
sid = os.getsid(pid)
print ( "Session id of the current process:" , sid)
pid = 10
sid = os.getsid(pid)
print ( "Session id of the process whose process id is % d:" % pid, sid)
|
Output:
Share your thoughts in the comments
Please Login to comment...