Monday, November 18, 2024
Google search engine
HomeLanguagesPython | os.WSTOPSIG() method

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




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


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

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments