UNIX用唯一的被称为进程ID(process ID)的证书值来标识进程。每个进程还有一个父进程ID(parent process ID)利用os模块可以返回这两个id值。建立outputPID.py文件,内容如下:
#!/usr/bin/env python
import os
def main():
print "I am process %d\n" % os.getpid()
print "My parent is %d\n" % os.getppid()
if __name__=="__main__":
main()
输出结果如下:
[root@localhost ~]# ./outputPID.py
I am process 3711
My parent is 2419
os.getpid()返回当前进程id值,os.getppid()返回当前进程的父进程PID值。
返回一个进程的组ID和用户ID分别使用os.geteuid()与os.geteuid(),而os.getgid(),os.getegid()分别返回进程的真实组ID与有效组ID。建立outputIDs.py 文件,内容如下:
#!/usr/bin/env python
import os
def main():
print "My real user ID is %d\n" % os.getuid()
print "My effective user ID is %d\n" % os.geteuid()
print "My read group ID is %d \n" % os.getgid()
print "My effective group ID is %d \n" % os.getegid()
if __name__=="__main__":
main()
以下是运行结果:
[root@localhost ~]# ./outputIDs.py
My real user ID is 0
My effective user ID is 0
My read group ID is 0
My effective group ID is 0
阅读(1427) | 评论(0) | 转发(0) |