Python os.tcsetpgrp() 方法



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!!
python_files_io.htm
廣告