Python | os.WCOREDUMP() 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.WCOREDUMP()
method in Python is used to check whether a core dump was generated for the process. This method takes process status code as returned by os.wait()
, os.system()
or os.waitpid()
method as a parameter.
Syntax: os.WCOREDUMP(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 a boolean value of class ‘bool’. True is returned if core dump was generated for the process, otherwise returns False.
Code #1: Use of os.WCOREDUMP()
method
import os
pid = os.fork()
if pid :
info = os.wait()
print ( "\nIn parent process" )
core_dump = os.WCOREDUMP(info[ 1 ])
print ( "Was core dump generated?" , core_dump)
else :
print ( "In Child process" )
print ( "Process ID:" , os.getpid())
print ( "Hello ! Geeks" )
os.abort()
|
Output:
In Child process
Process ID: 15059
Hello! Geeks
In parent process
Was core dump generated? True
Code #2: Use of os.WCOREDUMP()
method
import os
pid = os.fork()
if pid :
pid2 = os.fork()
if pid2 :
child1_info = os.waitpid(pid, 0 )
child2_info = os.waitpid(pid2, 0 )
print ( "\nIn parent process" )
core_dump = os.WCOREDUMP(child1_info[ 1 ])
print ( "Was core dump generated for first child process?" )
print (core_dump)
core_dump = os.WCOREDUMP(child2_info[ 1 ])
print ( "\nWas core dump generated for second child process?" )
print (core_dump)
else :
print ( "\nIn second child process" )
print ( "Process id:" , os.getpid())
print ( "Hey ! there" )
print ( "Exiting" )
else :
print ( "In Child process" )
print ( "Process ID:" , os.getpid())
print ( "Hello ! Geeks" )
os.abort()
|
Output:
In first child process
Process ID: 16289
Hello! Geeks
In second child process
Process id: 16290
Hey! there
Exiting
In parent process
Was core dump generated for first child process?
True
Was core dump generated for second child process?
False
References: https://docs.python.org/3/library/os.html#os.WCOREDUMP
Share your thoughts in the comments
Please Login to comment...