Skip to main content
added 53 characters in body
Source Link
stason
  • 111
  • 5
  • remove | grep python if you want all processes
  • replace 2**10 with 2**20 and MB with GB if you want GBs instead of MBs
  • replace python with another string that your program starts with. You can inspect the output of ps auxc to 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.3f with %0.2f if you want only 2 decimals for MBs
  • replace watch -n 0.5 with watch -n 3 if 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 ps flags in these examples the count of columns may change and the scripts may break.
  • replace 2**10 with 2**20 and MB with GB if you want GBs instead of MBs
  • replace python with another string that your program starts with. You can inspect the output of ps auxc to 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.3f with %0.2f if you want only 2 decimals for MBs
  • replace watch -n 0.5 with watch -n 3 if 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 ps flags in these examples the count of columns may change and the scripts may break.
  • remove | grep python if you want all processes
  • replace 2**10 with 2**20 and MB with GB if you want GBs instead of MBs
  • replace python with another string that your program starts with. You can inspect the output of ps auxc to 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.3f with %0.2f if you want only 2 decimals for MBs
  • replace watch -n 0.5 with watch -n 3 if 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 ps flags in these examples the count of columns may change and the scripts may break.
added 61 characters in body
Source Link
stason
  • 111
  • 5

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.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.

a. withoutWithout headers (if you memorizedps's headers)

  • One time:

    ps auxc | grep python | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10'2**10; $_=qq[@F]' | column -t

  • Using watch to emulate like top, refreshing every 0.5 sec

    watch -n 0.5 $'ps auxc | grep python | perl -plae \'$F[5]=sprintf q[%0.3fMB],$F[5]/2**10\'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"2**10; \$_=qq[@F]" | column -t | grep python\''

b. withWith 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'2**10; $_=qq[@F]') | column -t

  • Using watch to 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\'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"2**10; \$_=qq[@F]") | column -t\''

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.

a. without headers

  • One time:

    ps auxc | grep python | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10' | column -t

  • Using watch to emulate like top, refreshing every 0.5 sec

    watch -n 0.5 $'ps auxc | grep python | perl -plae \'$F[5]=sprintf q[%0.3fMB],$F[5]/2**10\' | 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" | column -t | grep python\''

b. with headers

  • One time:

    (ps auxc | head -1; ps auxc | grep python | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10') | column -t

  • Using watch to 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\') | 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") | column -t\''

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.

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 -t

  • Using watch to emulate top, refreshing every 0.5 sec

    watch -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 -t

  • Using watch to 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\''

added 87 characters in body
Source Link
stason
  • 111
  • 5
  • One time:

    ps auxc | grep python | perl -laeplae '$F[4]=sprintf'$F[5]=sprintf q[%0.3fMB], $F[4]$F[5]/2**10; print qq[@F]'2**10' | column -t | grep python

  • Using watch to emulate like top, refreshing every 0.5 sec

    watch -n 0.5 'ps$'ps auxc | grep python | perl -laeplae "\$F[4]=sprintf\'$F[5]=sprintf q[%0.3fMB], \$F[4]$F[5]/2**10;2**10\' print| 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" | column -t | grep python'python\''

  • One time:

    (ps auxc | perlhead -ae1; 'pushps @x,qq[@F]auxc if| !@x;grep $F[5]=sprintfpython | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10; push @x,qq[@F] if $F[10]=~/python/; END {$,=qq[\n]; print @x}'2**10') | column -t

  • Using watch to emulate top, refreshing every 0.5 sec:

    watch -n 0.5 'ps$'(ps auxc | perlhead -ae "push @x,qq[@F]1; ifps !@x;;auxc \$F[5]=sprintf| q[%0.3fMB],\$F[5]/2**10;grep pushpython @x,qq[@F]| ifperl \$F[10]=~/python/;-plae END\'$F[5]=sprintf {\$q[%0.3fMB],=qq[\n]; print @x}"$F[5]/2**10\') | column -t'

  • makeMake an alias (bash 4.4 or higher)

    alias watch-python=$'watch -n 0.5 \'ps\'(ps auxc | perlhead -ae1; "pushps @x,qq[@F]auxc if| !@x;grep \$F[5]=sprintfpython | perl -plae "\$F[5]=sprintf q[%0.3fMB],\$F[5]/2**10; push @x,qq[@F] if \$F[10]=~/python/; END {\$,=qq[\n]; print @x}"2**10") | column -t\''

  • replace 2**10 with 2**20 and MB with GB if you want GBs instead of MBs
  • replace python with another string that your program starts with. You can inspect the output of ps auxc to 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.3f with %0.2f if you want only 2 decimals for MBs
  • replace watch -n 0.5 with watch -n 3 if 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 ps flags in these examples the count of columns may change and the scripts may break.
  • One time:

    ps auxc | perl -lae '$F[4]=sprintf q[%0.3fMB], $F[4]/2**10; print qq[@F]' | column -t | grep python

  • Using watch to emulate like top, refreshing every 0.5 sec

    watch -n 0.5 'ps auxc | perl -lae "\$F[4]=sprintf q[%0.3fMB], \$F[4]/2**10; print qq[@F]" | column -t | grep python'

  • One time:

    ps auxc | perl -ae 'push @x,qq[@F] if !@x; $F[5]=sprintf q[%0.3fMB],$F[5]/2**10; push @x,qq[@F] if $F[10]=~/python/; END {$,=qq[\n]; print @x}' | column -t

  • Using watch to emulate top, refreshing every 0.5 sec:

    watch -n 0.5 'ps auxc | perl -ae "push @x,qq[@F] if !@x;; \$F[5]=sprintf q[%0.3fMB],\$F[5]/2**10; push @x,qq[@F] if \$F[10]=~/python/; END {\$,=qq[\n]; print @x}" | column -t'

  • make an alias (bash 4.4 or higher)

    alias watch-python=$'watch -n 0.5 \'ps auxc | perl -ae "push @x,qq[@F] if !@x; \$F[5]=sprintf q[%0.3fMB],\$F[5]/2**10; push @x,qq[@F] if \$F[10]=~/python/; END {\$,=qq[\n]; print @x}" | column -t\''

  • replace 2**10 with 2**20 and MB with GB if you want GBs instead of MBs
  • replace python with another string that your program starts with. You can inspect the output of ps auxc to 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 watch -n 0.5 with watch -n 3 if 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 ps flags in these examples the count of columns may change and the scripts may break.
  • One time:

    ps auxc | grep python | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10' | column -t

  • Using watch to emulate like top, refreshing every 0.5 sec

    watch -n 0.5 $'ps auxc | grep python | perl -plae \'$F[5]=sprintf q[%0.3fMB],$F[5]/2**10\' | 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" | column -t | grep python\''

  • One time:

    (ps auxc | head -1; ps auxc | grep python | perl -plae '$F[5]=sprintf q[%0.3fMB],$F[5]/2**10') | column -t

  • Using watch to 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\') | 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") | column -t\''

  • replace 2**10 with 2**20 and MB with GB if you want GBs instead of MBs
  • replace python with another string that your program starts with. You can inspect the output of ps auxc to 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.3f with %0.2f if you want only 2 decimals for MBs
  • replace watch -n 0.5 with watch -n 3 if 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 ps flags in these examples the count of columns may change and the scripts may break.
deleted 156 characters in body
Source Link
stason
  • 111
  • 5
Loading
Source Link
stason
  • 111
  • 5
Loading