刚刚发现ps
。我花了大约 20 分钟通读了一遍man ps
,测试了不同的选项,但发现自己对这些选项更加感兴趣,也深感困惑。我无法理解的顺序和格式ps [options]
,因此我向 Linux 和终端向导寻求建议。
我想要什么ps [options]
前 25 个进程按 排序%CPU
,然后%MEM
在以下列中:
USER TIME+ %CPU %MEM PID CMD
在--forest
ASCII 树样式的进程层次结构中。
top
本质上,是带有自定义列和样式流程层次结构的快照--forest
。
与我正在寻找的输出最接近的示例是通过引用top
和ps -eH --forest
例子:
%CPU
基本上就是这样,但通过和截断为前 25 个进程%MEM
,其中包含以下列:USER TIME+ %CPU %MEM PID CMD
... 1023 ? 00:00:00 lightdm 1056 tty7 00:01:55 \_ Xorg 1215 ? 00:00:00 \_ lightdm 1394 ? 00:00:00 \_ upstart 1461 ? 00:00:00 \_ upstart-udev-br 1464 ? 00:00:00 \_ dbus-daemon 1529 ? 00:00:00 \_ upstart-dbus-br 1533 ? 00:00:00 \_ upstart-file-br 1535 ? 00:00:00 \_ upstart-dbus-br 1538 ? 00:00:00 \_ at-spi-bus-laun 1543 ? 00:00:00 | \_ dbus-daemon 1545 ? 00:00:01 \_ at-spi2-registr 1555 ? 00:00:00 \_ gvfsd 1560 ? 00:00:00 \_ gvfsd-fuse 1599 ? 00:00:00 \_ gpg-agent 1684 ? 00:00:00 \_ sh 1695 ? 00:00:00 | \_ xfce4-session 1714 ? 00:00:08 | \_ psensor 1715 ? 00:00:16 | \_ python2 1824 ? 00:00:00 | | \_ gnome-pty-helpe 1825 pts/1 00:00:00 | | \_ zsh 8825 pts/1 00:00:00 | | | \_ man 8837 pts/1 00:00:00 | | | \_ less 4068 pts/2 00:00:00 | | \_ zsh 10783 pts/2 00:00:00 | | | \_ ps 6435 pts/7 00:00:00 | | \_ zsh 1716 ? 00:00:00 | \_ light-locker 1718 ? 00:00:01 | \_ nm-applet 1725 ? 00:00:00 | \_ polkit-gnome-au 1726 ? 00:00:00 | \_ update-notifier 1738 ? 00:00:01 | \_ applet.py 1699 ? 00:00:00 \_ xfconfd 1705 ? 00:00:11 \_ xfwm4 1709 ? 00:00:01 \_ xfce4-panel 1791 ? 00:00:00 | \_ panel-1-whisker 3837 ? 00:00:05 | | \_ go-for-it 3922 ? 00:00:03 | | \_ xfce4-keyboard- 5294 ? 00:01:29 | | \_ anki 1800 ? 00:00:00 | \_ xfce4-timer 1807 ? 00:00:16 | \_ panel-11-system 1810 ? 00:00:00 | \_ panel-4-systray 1814 ? 00:00:00 | \_ panel-5-power-m 1821 ? 00:00:04 | \_ panel-6-indicat 1711 ? 00:00:05 \_ Thunar 1713 ? 00:00:01 \_ xfdesktop 1717 ? 00:00:00 \_ xfsettingsd 1728 ? 00:00:00 \_ xfce4-volumed 1732 ? 00:00:00 \_ dconf-service 1748 ? 00:00:00 \_ xfce4-power-man 1754 ? 00:00:00 \_ pulseaudio 1802 ? 00:00:00 \_ gconfd-2 1841 ? 00:00:00 \_ gvfs-udisks2-vo 1851 ? 00:00:00 \_ upstart 1855 ? 00:00:00 | \_ indicator-messa 1856 ? 00:00:00 | \_ indicator-sound 1857 ? 00:00:00 | \_ indicator-appli 1853 ? 00:00:00 \_ gvfs-mtp-volume 1874 ? 00:00:00 \_ gvfs-goa-volume 1892 ? 00:00:00 \_ gvfs-afc-volume 1900 ? 00:00:00 \_ gvfs-gphoto2-vo 2214 ? 00:01:19 \_ chromium-browse 2222 ? 00:00:00 | \_ chromium-browse 2224 ? 00:00:00 | | \_ chromium-browse 2275 ? 00:00:03 | | \_ chromium-browse 2290 ? 00:00:01 | | \_ chromium-browse 2317 ? 00:00:00 | | \_ chromium-browse 2334 ? 00:00:01 | | \_ chromium-browse 10709 ? 00:00:01 | | \_ chromium-browse 2248 ? 00:00:55 | \_ chromium-browse 2262 ? 00:00:00 | \_ chromium-browse 3637 ? 00:00:00 \_ gvfsd-metadata 3641 ? 00:00:00 \_ gvfsd-trash 3848 ? 00:00:00 \_ gvfsd-network 3862 ? 00:00:00 \_ gvfsd-dnssd 10492 ? 00:00:01 \_ sublime_text 10502 ? 00:00:01 \_ plugin_host 1050 ? 00:00:00 wpa_supplicant ...
答案1
使用-o
选项ps
允许用户定义输出格式。我们还可以将此输出排序为“top-25”视图。ps ... --sort ...
但是,当选择a 时,不可能强加“森林”或进程层次结构选项。将 PPID 添加到输出可以暴露层次关系。
具体针对您的情况,我们可能会这样做:
ps -e -ouser,time,cpu,vsz,ppid,pid,cmd --sort -time,user | head -26
这将按时间降序(最大值,第一个)对输出进行排序,然后按用户在标题行下方给出 25 个“顶部”进程。