How could one determine UID/GID of running process

permissionstopuidunix-philosophy

Is there any way to retrieve UID/GID of running process?
Currently, I know only way of looking it up in htop. But I don't want to depend on third-party tool, prefer to use builtin unix commands.
Could you suggest a few useful oneliners?

This didn't satisfy my curiousity:

How to programmatically retrieve the GID of a running process

top shows only user but not the group.

Best Answer

$ stat -c "%u %g" /proc/$pid/
1000 1000

or

$ egrep "^(U|G)id" /proc/$pid/status
Uid:    1000    1000    1000    1000
Gid:    1000    1000    1000    1000

or with only bash builtins:

$ while read -r line;do [ "${line:1:2}" = "id" ] && echo $line;done < /proc/17359/status 
Pid: 17359
Uid: 1000 1000 1000 1000
Gid: 1000 1000 1000 1000
Related Question