Python 3.3+Linux · macOSosterm
os.waitid_result
os — waiting for processes
The result type of os.waitid(): a named tuple (si_pid, si_uid, …). Availability: Unix.
Syntax
os.waitid_result(...)
The fields come decoded: si_code says what happened (CLD_EXITED, CLD_KILLED, CLD_STOPPED), and si_status is the exit code or the signal number depending on si_code. So si_status must not be read without si_code. Like other os results it also behaves as a tuple.
Examples
import os
pid = os.fork() # → ? только Unix: 0 в дочернем процессе, PID потомка в родительском
if pid == 0: os._exit(5) # → ? потомок сразу завершается с кодом возврата 5
info = os.waitid(os.P_PID, pid, os.WEXITED) # → ? только Unix: объект os.waitid_result
print(info.si_status, info.si_code == os.CLD_EXITED) # → ? 5 True
print(info.si_pid == pid, info.si_uid == os.getuid()) # → ? True True
print(info[3]) # → 5 — это именованный кортеж: si_status доступен и по индексу
print(info.si_signo) # → ? номер сигнала SIGCHLD (на Linux 17) — waitid всегда сообщает именно о нём
See also
Open in the full glossarydocs.python.orgReport an inaccuracy