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

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically