我正在学习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似乎都有这个问题。