Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: mbt@ast.cam.ac.uk (Mark Taylor)
Subject: Re: Getting CPU usage % by program or shell ?
Date: 1998/07/20	[thread overview]
Message-ID: <6ovrta$sqb$1@pegasus.csx.cam.ac.uk> (raw)
In-Reply-To: 35b2eb51.18596790@10.101.200.105

JKChung (onions@doosan.com) wrote:

: Hi,

: I am using OSF/1 4.0b in Alpha 4100 and need to get
: CPU usage % as a return value by program or shell. 
: How do I do this? Thank you. 

If you like ugly C-shell scripts you could do something like this: 

  alias tosec awk -F: "'\\
    {mult=1; for (i=NF;i>0;i--) {sec += "\$"i * mult; mult *= 60} print sec }'"
  set cpu     = `ps -p $pid -otime  | tail -1 | tosec` 
  set elapsed = `ps -p $pid -oetime | tail -1 | tosec` 
  @ percent = ( 100 * $cpu ) / $elapsed

(this is over the lifetime of the process, not current usage a la top).

Mark

---------------------------------------------------------------------------
| Mark Taylor                       Institute of Astronomy, Cambridge, UK |
| mbt@ast.cam.ac.uk    http://dougal.chm.bris.ac.uk/~mbt/    01223 337535 |
---------------------------------------------------------------------------



      reply	other threads:[~1998-07-20  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-20  4:00 Getting CPU usage % by program or shell ? JKChung
1998-07-20  4:00 ` Mark Taylor [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox