Python os.wifcontinue() – Check if process continued from job control stop
Python os.wifcontinue() Method
The Python os.wifcontinue() method is used to check whether a process has been continued from a job control stop. This method takes the process status code returned by the os.wait(), os.system(), or os.waitpid() methods as an argument and returns True if the process has stopped, otherwise it returns False.
os.wifcontinue Syntax
os.wifcontinue (status)
os.wifcontinue Parameters
status: This parameter accepts the process status code (an integer value) returned by the os.system(), os.wait(), or os.waitpid() methods.
Return Type: This method returns a Boolean value of class ‘bool’. This method returns True if the process was continued from where job control left off, False otherwise.
os.wifcontinue example
Usage of os.wifcontinue() method
# Python program to explain os.WIFCONTINUED() 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
ifpid:
# Send signal 'SIGSTOP'
# to child process
# using os.kill() method
# signal 'SIGCONT' will cause
# the child process to stop
os.kill(pid, signal.SIGSTOP)
# Send signal 'SIGCONT'
# to child process
# using os.kill() method
# SIGCONT signal will cause
# the child process to continue
os.kill(pid, signal.SIGCONT)
# Get the child's pid and
# status code using
# os.waitpid() method
info = os.waitpid(pid, os.WCONTINUED)
# info is a tuple
# info[0] represents child's pid
# info[1] represents exit status code
Print("nIn parent process")
# Check whether the child process
# has been continued
# from a job control stop or not
# using os.WIFCONTINUED() method
Continued = os.WIFCONTINUED(info[1])
Print("Has child process been continued from a job control stop?")
Print(continued)
else :
Print("In Child process")
Print("Process ID:", os.getpid())
Print("Hello! Geeks")
Output:
In Child process
Process ID: 12371
Hello! Geeks
In parent process
Has child process been continued from a job control stop?
True