Python os.tcgetpgrp() Method
The Python os.tcgetpgrp() method is used to get the process group ID associated with the terminal represented by a given file descriptor. Generally, this file descriptor is obtained through the "os.open()" method.
In Python, a process group is a collection of one or more processes that are managed together.
Syntax
The syntax for Python os.tcgetpgrp() method is as follows −
os.tcgetpgrp(fd)
Parameters
The Python os.tcgetpgrp() method accepts a single parameter −
fd − This is the file descriptor.
Return Value
The Python os.tcgetpgrp() method returns the process group ID.
Example
The following example shows the usage of tcgetpgrp() method. Here, we are retrieving process group ID of "/dev/tty".
import os, sys
# Showing current directory
print ("Current working dir :%s" %os.getcwd())
# Changing dir to /dev/tty
fd = os.open("/dev/tty",os.O_RDONLY)
f = os.tcgetpgrp(fd)
# Showing the process group
print ("the process group associated is: ")
print (f)
os.close(fd)
print ("file closed successfully!!")
When we run above program, it produces following result −
Current working dir :/home/tp/Python the process group associated is: 3627 file closed successfully!!
python_files_io.htm
Advertisements