currently top of top
looks more or less like this:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
160932 username 20 0 236684 222504 6912 R 99,3 0,7 58:14.16 python3
6353 username 20 0 633904 523992 6656 R 99,0 1,6 13,39 python3
18092 username 20 0 393320 369180 11264 R 39,4 1,1 154:58.37 python3
149778 username 20 0 3975792 800884 301444 S 14,6 2,4 18:42.82 firefox
168196 username 20 0 2544432 181284 112904 S 7,0 0,6 0:08.15 Isolated Web Co
2065 root 20 0 1547428 353628 258444 S 3,3 1,1 63:27.48 Xorg
3103 mateusz 20 0 1206696 104704 39056 S 0,7 0,3 1:19.68 lxqt-panel
53 root -51 0 0 0 0 S 0,3 0,0 7:51.72 irq/9-acpi
834 root -51 0 0 0 0 S 0,3 0,0 9:44.32 irq/147-iwlwifi
1410 root 20 0 427404 4992 3968 S 0,3 0,0 3:00.38 thermald
I know I can use ps -fA | grep python
to distinguish python processes and use say ps -fA | grep 160932
to find one of top processes consuming my resources.
But how can I display it right in top
? Or how can I get top
-equivalent supporting this, preferably some relatively standard tool?
You can use the
c
command to toggle between showing the process name and command line. From the manpage:Once you use
c
to get a desired view, you can havetop
save this configuration by pressingW
. As mentioned above, you can start in the opposite of the saved configuration withtop -c
(ortop --cmdline-toggle
).This is more applicable if you're the author of those Python processes, but it's useful enough to mention here anyway.
With the setproctitle module, you can change the process name of your Python program.
You just
apt install python3-setproctitle
orpip install setproctitle
or something equivalent, and then:And then your process will be easily recognizable in process listings. It's a good idea to do this anyway, because it is useful in many situations, especially unexpected ones ;)