Python os.tcgetpgrp() 方法用于获取与给定文件描述符表示的终端关联的进程组 ID。通常,此文件描述符是通过 “os.open()” 方法获取的。
在 Python 中,进程组是一起管理的一个或多个进程的集合。
语法
Python os.tcgetpgrp() 方法的语法如下 -
os.tcgetpgrp(fd)
参数
Python os.tcgetpgrp() 方法接受单个参数 -
- fd − 这是文件描述符。
返回值
Python os.tcgetpgrp() 方法返回进程组 ID。
例以下示例显示了 tcgetpgrp() 方法的用法。在这里,我们检索了 “/dev/tty” 的进程组 ID。
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!!")
当我们运行上述程序时,它会产生以下结果——
Current working dir :/home/tp/Python
the process group associated is:
3627
file closed successfully!!
the process group associated is:
3627
file closed successfully!!