Python | os.WSTOPSIG() 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.

os.WSTOPSIG() method in Python is used to get the signal number which caused the process to stop. This method takes process status code as returned by os.wait(), os.system() or os.waitpid() method as a parameter and returns the signal number which caused the process to stop.

Syntax: os.WSTOPSIG(status)



Parameters:
status: This parameter takes process status code (an integer value) as returned by os.system(), os.wait() or os.waitpid() method.

Return type: This method returns an integer value which represents the signal number which caused the process to stop.

Code: Use of os.WSTOPSIG() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to explain os.WSTOPSIG() method 
  
# importing os and signal module  
import os, signal
  
# Create a child process
# using os.fork() method 
pid = os.fork()
  
  
# pid greater than 0
# indicates the parent process 
if pid :
      
  
    # send signal 'SIGSTOP'
    # to the child process
    # using os.kill() method
    # 'SIGSTOP' signal will
    # cause the process to stop
    os.kill(pid, signal.SIGSTOP) 
  
    # get the child's pid
    # and status code
    # using os.waitpid() method
    info = os.waitpid(pid, os.WSTOPPED)
  
    # os.waitpid() method
    # returns a tuple which
    # represents child's pid
    # and exit status code
  
    print("\nIn parent process")
  
    # Get the signal number due
    # to which child process stopped 
    # using os.WSTOPSIG() method
    stopSignal = os.WSTOPSIG(info[1]) 
      
    print("Child stopped due to signal no:", stopSignal)
    print("Signal name:", signal.Signals(stopSignal).name)
      
else :
    print("In child process")
    print("Process ID:", os.getpid())
    print("Hello ! Geeks")
    print("Exiting")

chevron_right


Output:

In Child process

In parent process
Child stopped due to signal no: 19
Signal name: SIGSTOP

References: https://docs.python.org/3/library/os.html#os.WSTOPSIG



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.