Python os.tcgetpgrp()方法

2019-10-16 23:05:11

Python的tcgetpgrp()方法返回與fd給出的終端關聯的行程群組(由os.open()返回的開啟的檔案描述符)。

語法

以下是tcgetpgrp()方法的語法 -

os.tcgetpgrp(fd)

引數

  • fd - 這是檔案描述符。

返回值

此方法返回行程群組。

範例

以下範例顯示了tcgetpgrp()方法的用法。

# !/usr/bin/python3
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 ("Closed the file successfully!!")

當執行上述程式時,它將在/tmp目錄中建立一個符號連結,如下所示: -

Current working dir is :/tmp
the process group associated is:
2670
Closed the file successfully!!