Python os.tcgetpgrp() 方法



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!!
python_files_io.htm
廣告
© . All rights reserved.