Python | os.waitid() 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.waitid()
method in Python is used by a process to wait for completion of one or more child processes.
Syntax: os.waitid(idtype, id, options)
Parameters:
id: An integer value representing the process id of child to wait on.
idtype: The idtype and id parameter specify which child the method waits for.
Return type: This method returns an object which represents the data contained in siginfo_t structure.
Code #1: Use of os.waitid()
method
import os
pid = os.fork()
if pid :
idtype = os.P_PID
id = pid
option = os.WEXITED
status = os.waitid(idtype, id , option)
print ( "\nIn parent process-" )
print ( "Status of child process:" )
print (status)
else :
print ( "In Child process-" )
print ( "Process ID:" , os.getpid())
print ( "Hello ! Geeks" )
print ( "Exiting.." )
|
Output:
In Child process-
Process ID: 10309
Hello! Geeks
Exiting..
In parent process-
Status of child process:
posix.waitid_result(si_pid=10309, si_uid=1000, si_signo=17, si_status=0, si_code=1)
Code #2: Use of os.waitid()
method
import os
pid = os.fork()
if pid :
pid2 = os.fork()
if pid2 :
idtype = os.P_ALL
id = pid
option = os.WSTOPPED | os.WEXITED
status = os.waitid(idtype, id , option)
print ( "\nIn parent process-" )
print ( "Status of completed child process:" )
print (status)
else :
print ( "\nIn Second Child process-" )
print ( "Process ID:" , os.getpid())
print ( "Hey ! There " )
print ( "Exiting" )
else :
print ( "In First Child process-" )
print ( "Process ID:" , os.getpid())
print ( "Hello ! Geeks" )
print ( "Exiting" )
|
Output:
In First Child process-
Process ID: 11524
Hello! Geeks
Exiting
In Second Child process-
Process ID: 11525
Hey! There
Exiting
In parent process-
Status of completed child process:
posix.waitid_result(si_pid=11524, si_uid=1000, si_signo=17, si_status=0, si_code=1)
References:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...