Python Glossary Русский

all Python 3Linux · macOSosfunction

os.tcgetpgrp

os — sessions and process groups

Return the process group controlling a terminal (by fd). Availability: Unix.

Syntax

os.tcgetpgrp(...)

It reports which process group is in the terminal's foreground, i.e. receives keyboard input and Ctrl+C signals. If it is not your group, the process runs in the background. A descriptor not attached to a terminal raises OSError.

Examples

import os
fd = os.open('/dev/tty', os.O_RDONLY)              # → ? только Unix: дескриптор управляющего терминала
print(os.tcgetpgrp(fd))                            # → ? только Unix: id группы процессов переднего плана, например 12345
print(os.tcgetpgrp(fd) == os.getpgrp())            # → ? True, если скрипт работает на переднем плане (запущен без &)
os.tcgetpgrp(os.open(os.devnull, os.O_RDONLY))     # → OSError: [Errno 25] Inappropriate ioctl for device — /dev/null не терминал

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy