Python Glossary Русский

all Python 3Linux · macOSosfunction

os.getpgid

os — sessions and process groups

Return the process-group id (PGID) of a given PID. Availability: Unix.

Syntax

os.getpgid(...)

A process group unites a pipeline started by a shell — all commands in cmd1 | cmd2, for example. The terminal sends Ctrl+C to the whole foreground group. Zero instead of a PID means the current process; a non-existent PID raises ProcessLookupError.

Examples

import os
pgid = os.getpgid(0)  # → ? только Unix: PGID текущего процесса, например 4711
print(os.getpgid(os.getpid()) == pgid)  # → ? только Unix: True — pid=0 означает «текущий процесс»
print(os.getpgid(0) == os.getpgrp())  # → ? только Unix: True — os.getpgrp() возвращает тот же PGID, но без аргумента
print(os.getpgid(os.getppid()))  # → ? только Unix: PGID родителя (обычно shell), например 4390
print(os.getpgid(999999))  # → ProcessLookupError: [Errno 3] No such process

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy