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.

Code: Use of os.getsid() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:
os.getsid() method output



My Personal Notes arrow_drop_up

self motivated and passionate programmer

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.