2

How to get the ruid (real user ID), euid (effective user ID), suid (saved user ID) and rgid (real group ID), egid (effective group ID), sgid (saved group ID) of a process, can it be done using ps?

4

With Debian's procps-ng:

$ ps -o pid,euid,ruid,suid,egid,rgid,sgid,cmd
  PID  EUID  RUID  SUID  EGID  RGID  SGID CMD
28793  1000  1000  1000  1000  1000  1000 -/bin/bash
...

Under STANDARD FORMAT SPECIFIERS in the man page:

euid        EUID      effective user ID (alias uid).
euser       EUSER     effective user name.  This will be the textual
                      user ID, if it can be obtained and the field
                      width permits, or a decimal representation
                      otherwise.

etc.

FreeBSD ps has svuid and svgid instead of suid and sgid and the one that comes with macOS only knows uid and gid for the effective UID and GID (not euid or egid).

On Linux, there's also the filesystem access UID and GID though it's probably not used much (see setfsuid(2)). The specifiers for those are fuid/fsuid and fgid/fsgid.

/proc/$pid/status also contains them, see proc(5)

  • ps is giving me: "ERROR: Unsupported option (BSD syntax)". – user264127 Dec 3 '17 at 22:26
  • @ilkkachu You've made a typo, "ps -opid..." should be "ps -o pid...". – user7681202 Dec 8 '17 at 23:37
  • @user7681202, works both ways on procps-ng and on the macOS BSD ps. Does it make a difference in some implementation? – ilkkachu Dec 8 '17 at 23:42
  • 1
    @ilkkachu Sorry, it works like you did too ("ps -opid..."). I thought it didn't work because I put a space after the commas. – user7681202 Dec 8 '17 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.