R
raocheng
We know that we can get process or file's uid/gid in python. For
example:
$ python
$ python
How can we get the user/group name from the uid/gid ?
Generally, we can get this information from /etc/passwd. But it is too
inconvenient and when we are using integrated password management, we
can not depend on /etc/passwd.
Thanks in advance.
example:
$ python
import os
os.getuid() 1516
os.getgid() 102
os.geteuid() 1516
os.getegid() 102
os.getgroups() [102, 600]
$ python
import os,stat
uid = os.stat("./file1")[stat.ST_UID]
gid = os.stat("./file1")[stat.ST_GID]
print uid, gid 1516 102
How can we get the user/group name from the uid/gid ?
Generally, we can get this information from /etc/passwd. But it is too
inconvenient and when we are using integrated password management, we
can not depend on /etc/passwd.
Thanks in advance.