CPU time per thread?

Shane Stainsby <[email protected]>
Newsgroups gmane.comp.lib.phil
Message-ID <[email protected]>
Hi,

On RH7.2 I obtain the per thread user, system and elapsed time by reading 
the kernel information from '/proc/<pid>/stat'.

I talked with Ian Wienand about this subject and he did a bit of digging on 
my behalf and discovered the following on RH9:

Tracing through fs/proc/base.c, it turns out that the threads are hidden in 
the /proc output.     Try doing ls -a in /proc, the threads should be 
visible with a '.' preceeding them.

The problem is getting the pid of the threads reliably; getpid is now 
returning tgid, which means threads get the parent processes id back.

There is a sys_gettid call which you can probably use syscall() for i 
guess, but I this doesn't seem to be exported from libc.

It's a bit of a pickle :( you can always enumerate through all (including 
hidden) pids and check the tgid field and manually correlate it, but that 
sucks.

So its seems that what I require is;

Replacement call to getpid() that returns the 'task id' used in creating 
the /proc/.XXXX file.
If different from RH7.2 a description of the fields in the /proc/.XXXX file.

If you need further clarification please do ask.

Cheers
Shane
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.