Python os.tcsetpgrp() 方法将与给定文件描述符表示的终端关联的进程组 ID 设置为整数值。此文件描述符是通过 “os.open()” 方法获取的。
注意:在 UNIX 等操作系统中,每个进程都属于一个特定的进程组。
语法
以下是 Python os.tcsetpgrp() 方法的语法 -
os.tcsetpgrp(fd, pg)
参数
Python os.tcsetpgrp() 方法接受以下参数 -
- fd − 这是文件描述符。
- pg − 这会将进程组设置为 pg。
返回值
Python os.tcsetpgrp() 方法不返回任何值。
例以下示例显示了 tcsetpgrp() 方法的用法。
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)
# Setting the process group
os.tcsetpgrp(fd,2672)
print ("done")
os.close(fd)
print ("Closed the file successfully!!")
当我们运行上述程序时,它会产生以下结果——
Current working dir is :/tmp
the process group associated is:
2672
done
Closed the file successfully!!
the process group associated is:
2672
done
Closed the file successfully!!