2016-05-30 378 views
-1

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

PID TTY   TIME CMD 
    26969 pts/34  0:00 man 
    27636 pts/2  0:00 awk 
    25215 pts/35  0:00 bash 

我想它是与此类似:

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 

列顺序并不重要

回答

1

用途:

ps a -o pid,tty,etime,cmd,user 

ps手册:

SIMPLE进程选择

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

当与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 

与GNU风格--sort 选项。

For example: ps -eo pid,user,args --sort user 
+0

即使一些关键字,如“TT”是不行的(应该是TTY我猜的)我现在明白了吧。但如何与-a选项一起使用它?因为即使像“?”这样的终端的价值也显示所有的处理这意味着该过程没有控制终端。我可以使用grep,但在ps命令中应该有一个带-a选项的解决方案 – wooden

+0

好的,检查我的编辑@wooden – klashxx

+0

它说-o选项是非法的。我找到了我的解决方案:ps -af – wooden

0

我发现PS -af工作的方式我想