0

I have tried this but doesn't work ps -eo euser,ruser,suser,fuser,f,comm,label | grep processname

can anyone show me the right way to do this?

  • grep -i pid /proc/pidof processname/status ? – SHW Sep 29 '16 at 8:40
  • put pidof procesname in a pair of backtick – SHW Sep 29 '16 at 8:41
  • @SHW will try and get back – RaGa__M Sep 29 '16 at 8:42
  • @SHW noway to do with the PS itself? – RaGa__M Sep 29 '16 at 8:42
  • @SHW No doesn't kick in i tried this "grep -i pid /proc/0000/status" and grep -i 0000 /proc/0000/status – RaGa__M Sep 29 '16 at 8:50
2

You are trying to map Linux ps options and field name to FreeBSD ps options and keywords : this is one of the main obvious differences between a linux-like system and a BSD-style one.

First the -e option on FreeBSD ps means "Display the environment as well". What you want is in fact displaying all processes, that is -ax for FreeBSD; -x is to display also processes without a controlling terminal (kernel processes and daemons) and the default behavior is not to display them.

Regarding Linux ps about per field selection (from man ps):

 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. The n option can be used to force the decimal
                     representation. (alias uname, user).
 ruser      RUSER    real user ID. This will be the textual user ID, if it can be obtained and the field width permits,
                    or a decimal representation otherwise.
 suser      SUSER    saved user name. This will be the textual user ID, if it can be obtained and the field width permits,
                     or a decimal representation otherwise. (alias svuser).
 fuser      FUSER    filesystem access user ID. This will be the textual user ID, if it can be obtained and the field
                     width permits, or a decimal representation otherwise.
 f          F        flags associated with the process, see the PROCESS FLAGS section. (alias flag, flags).
 comm       COMMAND  command name (only the executable name). Modifications to the command name will not be shown.
                     A process marked <defunct> is partly dead, waiting to be fully destroyed by its parent. The output in
                     this column may contain spaces. (alias ucmd, ucomm). See also the args format keyword, the -f option,
                     and the c option.
                     When specified last, this column will extend to the edge of the display. If ps can not determine
                     display width, as when output is redirected (piped) into a file or another command, the output width
                     is undefined. (it may be 80, unlimited, determined by the TERM variable, and so on) The COLUMNS
                     environment variable or --cols option may be used to exactly determine the width in this case. The w
                     or -w option may be also be used to adjust width.
 label      LABEL    security label, most commonly used for SE Linux context data. This is for the Mandatory Access
                     Control ("MAC") found on high-security systems.

From FreeBSD ps manual about per keyword selection:

 uid        effective user ID (alias euid)
 user       user name (from UID)
 ruid       real user ID
 ruser      user name (from ruid)
 svuid      saved UID from a setuid executable
 state      symbolic process state (alias stat)
 comm       command
 label      MAC label

There is no obvious FreeBSD equivalent to fuser, so let's skip it.

So, in your case it would translate to:

ps -axo user,ruser,svuid,state,comm,label |grep <process_name>

| improve this answer | |
  • phenomenal Answer!!! – RaGa__M Sep 29 '16 at 10:57
0

And here's how to do it without ps:

awk '{ 
    if ("awk" == $1) 
        print "PID:",$2,"EUID:",$12,"EGID:",$13,"Groups:",$14; 
}' /proc/*/status

Substitute for "awk" in the if test as appropriate. Remove the if test and substitute a specific process ID for * if you want to inspect a specific process.

| improve this answer | |
  • WARNING: procfs is not mounted by default on a FreeBSD system AND there is no SVUID or RUID info into the /proc/<current_proc>/status meta file ! – Ouki Sep 29 '16 at 12:23
  • 1
    It is if one has installed TrueOS/PC-BSD. – JdeBP Sep 29 '16 at 17:48

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.