0

Just discovered ps. Spent about 20 minutes reading through the man ps, testing out different options, but only found myself both more intrigued and deeply perplexed by the options. The ordinality and formatting of ps [options] escapes me, so I'm calling on the linux & terminal wizards for advice.

What I'd like from ps [options]

The top 25 processes sorted by %CPU, then %MEM in the following columns:

USER TIME+ %CPU %MEM PID CMD

In the --forest ASCII tree style process hierarchy.


Essentially, a snapshot of top, with custom columns, with the --forest style process hierarchy.

The closest examples to the output I'm looking for would be by referencing top and ps -eH --forest

Example:

So basically this, but truncated to the top 25 processes by %CPU and %MEM, with the columns: 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 Answer 1

0

Using the -o option of ps allows a user-defined output format. We can also sort this output for a "top-25" view. The imposition of a "forest" or process hierarchy option isn't possible when a ps ... --sort ... is chosen, though. Adding PPID to the output can expose hierarchical relationships.

Specifically in your case, we might do:

ps -e -ouser,time,cpu,vsz,ppid,pid,cmd --sort -time,user | head -26

This orders the output in order of descending time (largest value, first) and then by user within to give 25 "top" processes beneath a header line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .