OS File 中的 os.tcsetpgrp(fd, pg)函

首页 / Python2入门教程 / OS File 中的 os.tcsetpgrp(fd, pg)函

Python方法tcsetpgrp()将与fd(由os.open()返回的打开文件描述符)给定的终端相关联的进程组设置为pg。

os.tcsetpgrp(fd, pg) - 语法

os.tcsetpgrp(fd, pg)
  • fd   -  这是文件描述符。

  • pg   -  将进程组设置为pg。

os.tcsetpgrp(fd, pg) - 示例

以下示例显示tcsetpgrp()方法的用法。

# !/usr/bin/python

import os, sys

# 显示当前目录
print "Current working dir :%s" %os.getcwd()

# 将目录更改为 /dev/tty
fd=os.open("/dev/tty",os.O_RDONLY)

f=os.tcgetpgrp(fd)

# 显示进程组
print "the process group associated is: "
print f

# 设置进程组
os.tcsetpgrp(fd,2672)
print "done"

os.close(fd)
print "Closed the file successfully!!"

当无涯教程运行上面的程序时,它产生以下输出-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-tcsetpgrp.html

来源:LearnFk无涯教程网

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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

硅谷产品实战36讲 -〔曲晓音〕

如何做好一场技术演讲 -〔极客时间〕

RPC实战与核心原理 -〔何小锋〕

SRE实战手册 -〔赵成〕

视觉笔记入门课 -〔高伟〕

React Hooks 核心原理与实战 -〔王沛〕

去无方向的信 -〔小麥〕

零基础学Python(2023版) -〔尹会生〕

现代C++20实战高手课 -〔卢誉声〕

好记忆不如烂笔头。留下您的足迹吧 :)