Python 3 - os.tcgetpgrp() 方法

  • 描述

    方法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!!")
    
  • 结果

    当我们运行上面的程序时,它会产生以下结果 -
    
    Current working dir is :/tmp
    the process group associated is:
    2670
    Closed the file successfully!!