Let's do some magic one liners so that you can alias what you want and never need to remember which letter to hit when in top to get what you want.
The want is to display top like output but having RSS in MBs and I'm adding also a desire to filter out only the program I want.
In the following examples we will use python as the target processes we want to watch. We will, of course, use perl to do that ;)
a. Without headers (if you memorizedps's headers)
One time:
ps auxc | grep python | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10; $_=qq[@F]' | column -tUsing
watchto emulate top, refreshing every 0.5 secwatch -n 0.5 $'ps auxc | grep python | perl -plae \'$F[5]=sprintf q[%0.3fMB],$F[5]/2**10; $_=qq[@F]\' | column -t'Make an alias (bash 4.4 or higher)
alias watch-python=$'watch -n 0.5 \'ps auxc | grep python | perl -plae "\$F[5]=sprintf q[%0.3fMB],\$F[5]/2**10; \$_=qq[@F]" | column -t | grep python\''
b. With headers (for the rest of us):
One time:
(ps auxc | head -1; ps auxc | grep python | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10; $_=qq[@F]') | column -tUsing
watchto emulate top, refreshing every 0.5 sec:watch -n 0.5 $'(ps auxc | head -1; ps auxc | grep python | perl -plae \'$F[5]=sprintf q[%0.3fMB],$F[5]/2**10; $_=qq[@F]\') | column -t'Make an alias (bash 4.4 or higher)
alias watch-python=$'watch -n 0.5 \'(ps auxc | head -1; ps auxc | grep python | perl -plae "\$F[5]=sprintf q[%0.3fMB],\$F[5]/2**10; \$_=qq[@F]") | column -t\''
Notes:
- replace
2**10with2**20andMBwithGBif you want GBs instead of MBs - replace
pythonwith another string that your program starts with. You can inspect the output ofps auxcto see what's the 10th (0-indexed) column says in case you get no output. a python program could be running with the name of the python script and not python itself for example, so make sure to use the name of the script instead. - replace
%0.3fwith%0.2fif you want only 2 decimals for MBs - replace
watch -n 0.5withwatch -n 3if you want to refresh every 3 seconds - these were tested with bash 5.1.16 - should work with most recent bash versions
- if you tweak the
psflags in these examples the count of columns may change and the scripts may break.