Python os.tcgetpgrp() Method
os.tcgetpgrp() Overview
The os.tcgetpgrp() method is used to return the process group associated with the terminal fd (an open file descriptor returned by os.open()).
os.tcgetpgrp() Syntax
The syntax format of the tcgetpgrp() method is as follows.
os.tcgetpgrp(fd)
os.tcgetpgrp() Parameters
- fd – File descriptor.
os.tcgetpgrp() Return Value
This method returns the process group.
os.tcgetpgrp() Example#1
The following example demonstrates the use of the tcgetpgrp() method.
Get the/dev/tty file and get the file descriptor associated with it using os.open() method.
‘/dev / tty’ is a special file which represents the controlling terminal of the current process.
Get the process group associated with the terminal given by the specified file descriptor the specified file descriptor using os.tcgetpgrp() method.
import os
fd = os.open("/dev/tty", os.O_RDWR)
pgid = os.tcgetpgrp(fd)
print("Process group associated with controlling\n \
terminal of the current process by os.tcgetpgrp:", pgid)
os.close(fd)
Output: