如何取得進程的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 。*

相關內容