From: Kero Date: 2005-11-11T17:37:14+09:00 Subject: Re: [SORTA OT] Getting CPU usage of a process >> > I'd like to be able to get the CPU usage of a particular process. >> > What are my options for doing so from Ruby? >> > >> > And would I want to use the elapsed real cpu time? Or the sum of the >> > elapsed user and system cpu time? (and then I believe I divide that >> > by the elapsed wall clock time) >> >> man proc, look for "/proc/[number]/stat" >> It contains a set of times spent by the process and its children. >> it also contains the starttime, so this should allow you to compute "Cpu >> usage of the process". > > Would I take the sum of the elapsed user and system cpu time and > divide that by the elapsed wall clock time to get the current cpu > percentage? That's what I would start with. Then you'll want to remember values of 'some time ago' so you can do the computation 'over the last some-time', as well as 'from the start of the process'. +--- Kero ---------------------------------- kero@chello@nl ---+ | The last good thing written in C++ was the Pachelbel Canon | | Jerry Olson | +--- M38c ------------ http://members.chello.nl/k.vangelder ---+