From: Barbier de Reuille Pierre
Date: 2006-01-11T07:53:02+09:00
Subject: Re: Finding CPU% of a linux task
Well, on Linux 2.6, the list of the threads is in :
/proc/[pid]/task
But it is not true for Linux 2.4 :(
And on 2.4, I really don't know if you can tell a process from a thread
from the exterior. At least, I see no difference in the /proc virtual
system.
But then, this discussion should be in
comp.os.linux.development.system, isn't it ?
Pierre
On Wed, 11 Jan 2006 06:42:54 +0900
Joe Van Dyk wrote:
> 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.
>
>
--
Do not sleep in a eucalyptus tree tonight.