如何获取进程的RUSER和EUSER(FreeBSD)

如何获取进程的RUSER和EUSER(FreeBSD)

我已经尝试过但不起作用ps -eo euser,ruser,suser,fuser,f,comm,label | grep processname

谁能告诉我正确的方法来做到这一点?

答案1

您正在尝试将 Linuxps选项和字段名称映射到 FreeBSDps选项和关键字:这是类 linux 系统和 BSD 风格系统之间的主要明显区别之一。

首先-eFreeBSD 上的选项ps意味着“同时显示环境”。你想要的实际上是显示所有进程,对于-axFreeBSD 来说; -x是也显示没有控制终端的进程(内核进程和守护进程),默认行为是不显示它们。

关于 Linux 的ps每个字段选择(来自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.

来自 FreeBSDps手册中关于每个关键字选择的介绍:

 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

没有明显的 FreeBSD 等同于定影器,所以我们跳过它。

所以,在你的情况下,它将转化为:

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

答案2

以下是如何在没有以下情况的情况下做到这一点ps

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

"awk"在测试中if酌情替换。如果您想检查特定进程,请删除if测试并替换为特定进程 ID 。*

相关内容