From: Joe Van Dyk Date: 2006-01-11T06:42:54+09:00 Subject: Re: Finding CPU% of a linux task On 1/10/06, James Edward Gray II wrote: > On Jan 10, 2006, at 3:31 PM, Joe Van Dyk wrote: > > > However, that doesn't capture threads or forked processes. If a > > program starts a couple threads (or forks a child process), I then > > have to figure out the cpu percentage of each of the child threads > > (and their childs and their child's childs, and so on) and add them > > together to get a total for the process. > > Ruby's threads are in process, so they should already be in your > percentage, shouldn't they? To clarify, these aren't Ruby processes I'm tracking. Sample usage of my class: pi = ProcessInfo.new pi.cpu_percentage # returns the cpu % of the process pi.running? # sees if the process is still running etc I added ProcessInfo#child_tasks, that searches /proc for all child tasks of the process. But then, when I calculate the cpu% of the process, I need to recursively go in and get all the cpu% of all the child threads/processes of the process. And my code got ugly fast.