问题:

如何显示调用该命令的用户?

如何显示与进程关联的用户ID?

解决方案

PS命令将打印与系统上任何进程关联的任何用户ID。
要查看当前在Linux系统上运行的所有进程,可以使用“ps”命令。

ps命令使用的最常见选项是“aux”:

$ps aux

上面的命令将显示系统上的每个进程,将包括以下信息:

USER: effective user id of a process owner
    PID: associated process ID
    %CPU: CPU time utilization by a process
    %MEM: Memory ( 内存 ) utilization by a process
    VSZ: virtual memory size of the process in KiB
    RSS: resident set size, the non-swapped physical memory that a task has used
    TTY: terminal associated with the process
    STAT: process state such as running or sleeping
    START: time when the command started
    TIME: cumulative CPU time
    COMMAND: the actual command that started this particular process

只输出与特定用户关联的进程:

$ps -U root

要搜索任何特定的进程名称,我们可以使用grep过滤:

$ps aux | grep init
root     1  0.0  0.0   2876   668 ?    Ss   Feb25   0:02 /sbin/init
日期:2020-07-07 20:56:08 来源:oir作者:oir