os.tcsetpgrp(fd, pg)
fd -- 這是在檔案描述符
pg -- 這將設定行程群組為pg
# !/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) # 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!!