Python Glossary Русский

all Python 3Linux · macOSosfunction

os.WTERMSIG

os — status decoding (W*)

Return the signal number that terminated a child. Availability: Unix.

Syntax

os.WTERMSIG(...)

It is meaningful only after WIFSIGNALED is true. The number converts to a name easily: signal.Signals(os.WTERMSIG(status)).name gives, for example, 'SIGTERM'. Signal 9 (SIGKILL) cannot be caught, so the program had no chance to save anything before dying.

Examples

import os
print(os.WTERMSIG(9))   # → 9 — статус процесса, убитого сигналом SIGKILL
print(os.WTERMSIG(15))   # → 15 — SIGTERM, обычное завершение по kill без -9
pid, status = os.wait()   # → ? только Unix: дождаться дочернего процесса и получить его статус
print(os.WTERMSIG(status) if os.WIFSIGNALED(status) else 0)   # → ? только Unix: номер сигнала, убившего ребёнка, или 0, если он завершился сам
print(os.WTERMSIG(256))   # → 0 — сигнала не было, 256 это выход с кодом 1; сначала проверяют WIFSIGNALED

See also

Open in the full glossarydocs.python.orgReport an inaccuracy