如何使 ps 命令显示用户、PID、终端、CMD

woo*_*den 4 unix shell

我需要使用显示与终端相关的所有进程的命令。ps -a 看起来不错,只是没有打印用户名。该命令打印:

  PID TTY         TIME   CMD
  26969 pts/34      0:00 man
  27636 pts/2       0:00 awk
  25215 pts/35      0:00 bash
Run Code Online (Sandbox Code Playgroud)

我希望它与此类似:

  PID   TTY         TIME CMD  USER  
  26969 pts/34      0:00 man  name
  27636 pts/2       0:00 awk  name
  25215 pts/35      0:00 bash name
Run Code Online (Sandbox Code Playgroud)

列顺序并不重要

Jua*_*doy 11

使用:

ps a -o pid,tty,etime,cmd,user
Run Code Online (Sandbox Code Playgroud)

来自ps手册:

简单的工艺选择

   a    ... An alternate description is that this option causes ps to list all processes with a terminal (tty), or to list all processes
Run Code Online (Sandbox Code Playgroud)

与 x 选项一起使用时。

标准格式说明符

   Here are the different keywords that may be used to control the output format (e.g. with option -o) or to sort the selected processes
Run Code Online (Sandbox Code Playgroud)

使用 GNU 风格的 --sort 选项。

   For example:  ps -eo pid,user,args --sort user
Run Code Online (Sandbox Code Playgroud)