Reputation: 8885
I am parsing process details from /proc/PID
and I am so far unable to find out who owns a process from that meta directory's files.
Documentation does not seem to point to that info as well.
Upvotes: 6
Views: 8816
Reputation: 40830
The user and group IDs (real, effective, saved set, and filesystem) are listed in /proc/<PID>/status>
, in the row which begins with Uid:
. Looking at the ownership of /proc/<PID>
is unreliable for the reasons listed in the manual page, namely the owner depends on the value of the process's "dumpable" attribute.
Upvotes: 4
Reputation: 94
The owner of the files in /proc/[pid]/ is not always the user -- programs can e.g. make themselves "non-dumpable" to avoid leaking sensitive information if they become another user, and then the file ownership of the files in the directory can change to root.
But normally the UID of the process can be retrieved by an fstat call (or a stat command ) on the /proc/[pid] directory itself.
Upvotes: 4
Reputation: 17169
The owner of the process is the owner of all files in the /proc/PID
directory.
$ ls -l /proc/27595
total 0
dr-xr-xr-x 2 me users 0 Jul 14 11:53 attr
-r-------- 1 me users 0 Jul 14 11:53 auxv
...
Also the file /proc/PID/loginuid
holds the UID of the owner of the process.
$ cat /proc/27595/loginuid
1000
Upvotes: 5