I try to determine which group(s) a running child process has inherited. I want to find all groups the process is in for his uid. Is there a way to determine this via /proc filesystem?
The list of groups is given under
/status; for example,
$ grep '^Groups' /proc/$$/status Groups: 4 24 27 30 46 110 115 116 1000
The primary group is given under
$ grep '^Gid' /proc/$$/status Gid: 1000 1000 1000 1000
ps is also capable of showing the groups of a process, as the other answers indicate.
$ ps -o group,supgrp $$ GROUP SUPGRP muru adm,cdrom,sudo,dip,www-data,plugdev,lpadmin,mlocate,sambashare,lxd,libvirtd,docker,muru
man ps, the output columns used for
egid EGID effective group ID number of the process as a decimal integer. (alias gid). egroup EGROUP effective group ID of the process. This will be the textual group ID, if it can be obtained and the field width permits, or a decimal representation otherwise. (alias group). gid GID see egid. (alias egid). group GROUP see egroup. (alias egroup). supgid SUPGID group ids of supplementary groups, if any. See getgroups(2). supgrp SUPGRP group names of supplementary groups, if any. See getgroups(2).
For the effective group id, real group id and supplementary group ids (as used for access control):
ps -o gid,rgid,supgid -p "$pid"
rgid are fairly portable,
supgid less so (all 3 would be available with the
ps from procps as typically found on Linux-based systems).
supgrp can be used to translate group ids to group names, but note that for group ids that have several corresponding group names, only one of them will be shown (same as for
ls -l vs
ls -n or anything that deals with user or group names based on ids).
For the process group id (as used for terminal job control):
ps -o pgid -p "$pid"