From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,c89bdfa4f6c77c1a X-Google-Attributes: gidfee84,public From: mbt@ast.cam.ac.uk (Mark Taylor) Subject: Re: Getting CPU usage % by program or shell ? Date: 1998/07/20 Message-ID: <6ovrta$sqb$1@pegasus.csx.cam.ac.uk>#1/1 X-Deja-AN: 373209908 References: <35b2eb51.18596790@10.101.200.105> Organization: University of Cambridge, England Newsgroups: comp.unix.osf.osf1 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 | ---------------------------------------------------------------------------