Change language

Python | os.WIFSTOPPED () method

os.WIFSTOPPED() in Python is used to check if a process has stopped. This method accepts the process status code returned by os.wait() , os.system () or os.waitpid() as a parameter and returns True if the process was stopped , otherwise it returns False.

Syntax: os.WIFSTOPPED (status)

Parameter:
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 a boolean value of class ’bool’. This method returns True if the process has been stopped, otherwise returns False.

Code: using the os.WIFSTOPPED ( )

# Python program to explain the os.WIFSTOPPED () method

 
# OS and signal module import

import os, signal

  
# Create a child process
# using the os.fork () method

pid = os.fork ()

  

  
# pid large e 0
# refers to the parent process

if pid:

 

  # Send signal & # 39; SIGSTOP & # 39;

# child process

  # using the os.kill () method

# the signal will call the child

  # stop the process

os. kill (pid, signal.SIGSTOP)

 

# Get the child’s pid and

  # status code using

# os. waitpid () method

info = os.waitpid (pid, os.WSTOPPED)

 

# info is a tuple

# info [0] represents the child’s pid

# info [1] represents the exit status code

 

print ( "In parent process" )

 

  # Checking the child process

  # was stopped or not

  # using the os.WIFSTOPPED () method

isStopped = os.WIFSTOPPED (info [ 1 ]) 

 

print ( "Has child process been stopped?" )

print (isStopped)

 

 

else < / code> :

print ( "In Child process" )

print ( "Process ID: " , os.getpid ())

  print ( " Hello! Geeks " )

  

Exit :

 In Child process Process ID: 10224 Hello! Geeks In parent process Has child process been stopped ? True 

Links: https://docs.python.org/3/library/os.html#os.WIFSTOPPED

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method