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
import os, signal
pid = os.fork()
if pid :
os.kill(pid, signal.SIGSTOP)
info = os.waitpid(pid, os.WSTOPPED)
print ( "\nIn parent process" )
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" )
|
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
Last Updated :
27 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...