os模块缺少python中的getresuid()方法

时间:2018-01-22 11:48:14

标签: python

我正在学习python。当我运行下面的代码时,我遇到了一些问题。似乎缺少os模块中的一些方法。这是代码:

import os
import time

print("process ruid is {}, euid is {}, suid is {}\ngid is {}, egid is{}, sgid is {}".format(*os.getresuid()+os.getresgid()))
pid = os.fork()
if pid:
    print("the main process euid is {}, gid is {}, id is {}, pgid is {}".format(os.geteuid(),os.getgid(), os.getpid(), os.getpgrp()))
    os._exit(0)  # kill original process
print("the child process euid is {}, gid is {}, id is {}, original pgid is {}".format(os.geteuid(),os.getgid(),os.getpid(), os.getpgrp()))
print "daemon started, now change the pgid of child process and let it become the leader process of a new group"
success =  os.setpgrp()
# success = os.setpgid(0, 0)
if success:
    print "get some problem here"
print("the child process euid is {}, gid is {}, id is {}, pgid is {}".format(os.geteuid(),os.getgid(),os.getpid(), os.getpgrp()))
time.sleep(10)
print "daemon terminated"


例外情况如下:

Traceback (most recent call last):
  File "Example/Example1_40.py", line 4, in <module>
    print("process ruid is {}, euid is {}, suid is {}\ngid is {}, egid is{}, sgid is {}".format(*os.getresuid()+os.getresgid()))
AttributeError: 'module' object has no attribute 'getresuid'


我用os在Python shell中测试dir(os)模块,我发现方法确实不存在。谁能告诉我,问题是什么。我正在研究macOS High Sierra 10.13.2,我使用Pyenv来安装Python。 Python2和Python3似乎都有这个问题。

0 个答案:

没有答案