【问题标题】:How to get short process name(cmd argument) in ps command of ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head如何在 ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | 的 ps 命令中获取短进程名称(cmd 参数)头
【发布时间】:2021-06-22 07:39:45
【问题描述】:

执行命令

ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head

我明白了:

 PID PPID %MEM %CPU CMD
   1555 1 4.2 0.2 /usr/sbin/mysqld
   2989 2735 3.9 4.0 /usr/bin/gnome-shell
   4785 2735 3.8 3.3 /opt/google/chrome/chrome
   5053 4803 3.6 1.4 /opt/google/chrome/chrome --type=renderer --field-trial-handle=14183456324498441308,5334468187998544589,131072 --lang=en-GB --enable-crash-reporter=e482c1e6-5c57-40e8 -bb27-910eab6576d7, --extension-process --origin-trial-disabled-features=SecurePaymentConfirmation --num-raster-threads=4 --enable-main-frame-before-activation --renderer-client-id=12 --no-v8-untrusted-code-mitigations --shared-files=v8_context_snapshot_data:100
   5054 4803 3.5 0.6 /opt/google/chrome/chrome --type=renderer --field-trial-handle=14183456324498441308,5334468187998544589,131072 --lang=en-GB --enable-crash-reporter=e482c1e6-5c57-40e8 -bb27-910eab6576d7, --extension-process --origin-trial-disabled-features=SecurePaymentConfirmation --num-raster-threads=4 --enable-main-frame-before-activation --renderer-client-id=13 --no-v8-untrusted-code-mitigations --shared-files=v8_context_snapshot_data:100
  

在上面的输出中,我只想看到 chromeopt/google/chrome/chrome 而不是完整的名称。

【问题讨论】:

    标签: linux ps


    【解决方案1】:

    根据ps man page标准格式说明符 部分,cmd 关键字是args 关键字的别名,它将显示命令及其所有参数。请改用comm 关键字,这将只显示命令名称。

    ps -eo pid,ppid,%mem,%cpu,comm --sort=-%mem | head

    如果命令名称没有完全显示,您也可以使用宽度说明符来指定显示的确切字符数(如果comm 是您的最后一列,则没有任何区别)

    ps -eo pid,ppid,%mem,%cpu,comm:20 --sort=-%mem | head

    【讨论】:

    • 非常感谢!我得到了想要的输出。
    猜你喜欢
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    • 2012-12-20
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 2014-10-01
    相关资源
    最近更新 更多