Python | os.WIFEXITED() method
Last Updated :
26 Aug, 2019
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.WIFEXITED()
method in Python is used to check whether the process exited using exit(2) system call. This method takes process status code as returned by os.system(), os.wait() or os.waitpid() method as parameter and returns True if the process exited using exit(2) system call, otherwise returns False.
Syntax: os.WIFEXITED(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 True if the process exited using exit(2) system call else returns False.
Code: Use of os.WIFEXITED()
method
import os
pid = os.fork()
if pid > 0 :
pid2 = os.fork()
if pid2 > 0 :
print ( "\nIn parent process" )
info1 = os.waitpid(pid, 0 )
info2 = os.waitpid(pid2, 0 )
if os.WIFEXITED(info1[ 1 ]) :
print ( "First child exited using exit(2) system call." )
else :
print ("First child does not exited using \
exit( 2 ) system call.")
if os.WIFEXITED(info2[ 1 ]) :
print ( "Second child exited using exit(2) system call." )
else :
print ("Second child does not exited using \
exit( 2 ) system call.")
else :
print ( "\nIn second child process" )
print ( "Process ID:" , os.getpid())
print ( "Hey ! there" )
print ( "Second child aborted" )
os.abort()
else :
print ( "In first child process" )
print ( "Process ID:" , os.getpid())
print ( "Hello ! Geeks" )
print ( "First child exiting.." )
os._exit( 5 )
|
Output:
In first child process
Process ID: 11614
Hello! Geeks
First child exiting..
In second child process
Process ID: 11615
Hey! there
Second child aborted
In parent process
First child exited using exit(2) system call.
Second child does not exited using exit(2) system call.
References: https://docs.python.org/3/library/os.html#os.WIFEXITED
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...