Python os.wait()方法
Python中的os.wait()方法被进程用来等待子进程的完成。
此方法返回一个包含其PID和退出状态指示的元组。子进程的退出状态由一个16位数字表示,其低字节是终止进程的信号数,高字节是退出状态(如果信号数为零)。
os.wait 语法
os.wait()
os.wait 参数
不需要参数。
返回类型:该方法返回一个元组,其中包含终止子进程的PID和退出状态指示。
os.wait 示例
使用os.wait()方法
# Python program to explain os.wait() method
# importing os module
import os
# Create a child process
# using os.fork() method
pid = os.fork()
# a Non-zero process id (pid)
# indicates the parent process
if pid :
# Wait for the completion of
# child process using
# os.wait() method
status = os.wait()
print("\nIn parent process-")
print("Terminated child's process id:", status[0])
print("Signal number that killed the child process:", status[1])
else :
print("In Child process-")
print("Process ID:", os.getpid())
print("Hello ! Geeks")
print("Exiting")
# using os.wait() method
# Parent process will wait till
# the completion of child process
# and then only it will
# begin its execution
输出:
In Child process-
Process ID: 6276
Hello! Geeks
Exiting
In parent process-
Terminated child's process id: 6276
Signal number that killed the child process: 0