Python Glossary Русский

all Python 3Linux · macOSosfunction

os.getsid

os — sessions and process groups

Return the session id (SID) of a given PID. Availability: Unix.

Syntax

os.getsid(...)

A session groups the process groups tied to one terminal: everything started in one terminal window usually belongs to one session. When the terminal closes, the session receives SIGHUP. Zero instead of a PID means the current process.

Examples

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

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy