os.abort()
in Python is used to generate a SIGABRT signal for the current process. On Unix, this method dumps the kernel, while on Windows, the process immediately returns an exit code 3.
This method does not call the Python signal handler registered for the SIGABRT signal with signal.signal ().
Syntax: os.abort ()
Parameter: No parameter is required.
Return type: This method does not return any value in the calling process.
Code # 1: Using the os.abort ()
# Python program to explain the os.abort () method # import of the os module import os print ( "Hello! Geeks " ) # os.abort () method # will generate & # 39; SIGABRT & # 39; # signal for current process # Unix core dump # will be done # On windows the process # will exit with exit code 3 os.abort () # How the process was interrupted # line after os.abort () statement # will not be executed. print ( "This will not be printed" ) |
Output:
Hello! Geeks Aborted (core dumped)
Code # 2: Using method os.abort()
# Python program to explain the os.abort () method # import of the os module import os, signal # Create a child process # using the os.fork () method pid = os.fork () # pid greater than 0 # indicates the parent process if pid & gt; 0 : # Parent process print ( "In Parent process" ) # Wait for completion # child process and get # its pid and exit status indication # using the os.wait () method info = os.wait () sig = os.WTERMSIG (info [ 1 ]) print ( " Child exited due to signal no: " , sig) print ( "Signal name:" , signal .Signals (sig) .name) else : # child process print ( "In child process" ) print ( "Process ID:" , os.getpid ()) print ( "Hello! Geeks " ) Terminate child process # by generating a SIGABRT signal # using the os.abort () method os.abort () |
Exit :
In child process Process ID: 13914 Hello! Geeks In Parent process Child stopped due to signal no : 6 Signal name: SIGABRT
Links: https://docs.python.org/3/library/os.html#os.abort