Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95011

Re: Linux script to get most expensive processes

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.python
Subject Re: Linux script to get most expensive processes
Date 2015-08-05 12:56 +0200
Organization PointedEars Software (PES)
Message-ID <3702826.bDmuSmBusV@PointedEars.de> (permalink)
References <87twsehkmk.fsf@Equus.decebal.nl>

Show all headers | View raw


Cecil Westerhof wrote:

> Under Linux I like to get the most expensive processes. The two most
> useful commands are:
>     ps -eo pid,user,pcpu,args --sort=-pcpu
> and:
>     ps -eo pid,user,pcpu,args --sort=-vsize
> 
> In my case I am only interested in the seven most expensive processes.
> For this I wrote the following script.

Don’t.  Use

  ps -eo pid,user,pcpu,args --sort=-pcpu | head -n 8

or

  ps -eo pid,user,pcpu,args --sort=-pcpu | sed -n '2,8p'

and the like instead.  (procps ps(1) also has an output modifier to omit
the headers, but I could not get that to work with the sorting just now.

[Thanks for pointing out the “--sort” option of *procps* ps(1) 3.3.10.
I was not aware of it, and had used

$ alias cpu
alias cpu='ps -ww aux | sort -nk3 | tail'

instead.]
 
> ========================================================================
> #!/usr/bin/env python3
> 
> import subprocess
> import sys
> 
> 
> def give_output(param):
>     output = subprocess.check_output(([
>         'ps',
>         '--columns={0}'               .format(max_line_length),
>         '-eo',
>         'pid,user,start_time,{0},args'.format(param),
>         '--sort=-{0}'                 .format(param)
>     ])).splitlines()
> […]
> ========================================================================
> 
> Is this a reasonable way to do this?

No.

> Getting the parameter is done quit[e] simple, but I did not think fancy 
> was necessary here.

It is not.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Linux script to get most expensive processes Cecil Westerhof <Cecil@decebal.nl> - 2015-08-04 22:19 +0200
  Re: Linux script to get most expensive processes Emile van Sebille <emile@fenx.com> - 2015-08-04 13:52 -0700
    Re: Linux script to get most expensive processes Cecil Westerhof <Cecil@decebal.nl> - 2015-08-04 23:30 +0200
      Re: Linux script to get most expensive processes MRAB <python@mrabarnett.plus.com> - 2015-08-04 23:00 +0100
        Re: Linux script to get most expensive processes Cecil Westerhof <Cecil@decebal.nl> - 2015-08-05 01:14 +0200
      Re: Linux script to get most expensive processes Emile van Sebille <emile@fenx.com> - 2015-08-04 15:12 -0700
        Re: Linux script to get most expensive processes Cecil Westerhof <Cecil@decebal.nl> - 2015-08-05 01:17 +0200
  Re: Linux script to get most expensive processes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-05 12:56 +0200
  Re: Linux script to get most expensive processes Laura Creighton <lac@openend.se> - 2015-08-06 06:06 +0200

csiph-web