Open In App

Python | os.getsid() method

Last Updated : 27 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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




# 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:
os.getsid() method output


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads