如何在没有“root”进程的情况下通过 top 显示进程的 CPU 时间

nom*_*nom 3 grep top ps awk sort

好的,所以我已经尝试了大约三个小时但没有成功。

你如何搜索/显示/使用top命令(或ps命令,如果它有效......)输出所有进程的列表,按 CPU 时间排序,不包括“root”拥有的进程。

我到目前为止的尝试:

top -b -S -n 1 | grep -v root
top -b -S -n 1 | egrep -ve root

ps -eo pid,user,args,etime,time,%cpu --sort etime | egrep -v root
Run Code Online (Sandbox Code Playgroud)

那以及在批处理模式下运行 top 的各种尝试,输出到文件并尝试awk/grep/sort通过它并根据 CPU 时间量对其进行正确排序(大多数情况下无法找到正确的列/设法以任何看似有用的方式对正确的列进行排序)。

如果这看起来有点混乱,请原谅我;tl;博士:

我只是想要一些方法来轻松阅读 top 而无需 root procs 并按 CPU 时间排序。

slm*_*slm 7

如果您想简单地排除某个用户出现在top您可以使用-u开关。一开始并不明显,但是如果您深入研究手册页,top您会注意到此开关也可以被否定以充当用户的排除列表。

但是,你需要确保你有一个合适的版本top可以做到这一点:

$ top -version
  procps-ng version 3.3.8
Run Code Online (Sandbox Code Playgroud)

摘自 top 的手册页

   -u | -U  :User-filter-mode as:  -u | -U number or name
        Display only processes with a user id or user name matching that 
        given.  The '-u' option matches on  effective user whereas  the  
        '-U' option matches on any user (real, effective, saved, or 
        filesystem).

        Prepending  an  exclamation  point ('!') to the user id or name 
        instucts top to display only processes with users not matching the 
        one provided.
Run Code Online (Sandbox Code Playgroud)

例子

在下面的命令中,我们排除了 user root!使用斜杠 ( \)避开感叹号 ( )至关重要。

$ top -u\!root
Run Code Online (Sandbox Code Playgroud)

     ss 顶部