Python Glossary Русский

all Python 3Linux · macOSosfunction

os.WIFEXITED

os — status decoding (W*)

Test whether a child exited normally (via exit). Availability: Unix.

Syntax

os.WIFEXITED(...)

The first check when decoding a status: only if it is true does WEXITSTATUS yield a meaningful code. A process killed by a signal did not exit normally, and WIFEXITED is false for it. Since Python 3.9 a single os.waitstatus_to_exitcode call replaces the whole decoding.

Examples

import os
pid = os.fork()  # → ? только Unix: 0 в дочернем процессе, pid потомка в родителе
if pid == 0: os._exit(3)  # потомок завершается штатно с кодом 3
_, status = os.waitpid(pid, 0)  # родитель дожидается потомка и получает его статус
print(os.WIFEXITED(status))  # → True — потомок вышел сам, через exit
print(os.WEXITSTATUS(status))  # → 3 — код возврата, читать его можно только при WIFEXITED
print(os.WIFEXITED(os.system('kill -9 $$')))  # → False — процесс убит сигналом, а не завершился сам

See also

Open in the full glossarydocs.python.orgReport an inaccuracy