Re: Using getpid() often, another way? [was Re: clone() <-> getpid() bug in 2.6?]

Linus Torvalds
2004-06-12T13:48:12Z

On Sat, 12 Jun 2004, Dominik Straßer wrote:
>
> I am facing the following problem:
> I want to sum up the time spent in the main thread + all threads that
> ever existed.
> getrusage dosn't work (and didn't do so in pre-NPTL-times) as the time
> spent in threads is not taken into account.

Hmm.. That's likely a bug. It definitely should work, but I guess the
self-reaping ends up meaning that the time never gets percolated to the
parent any more.

Ingo, any comments/ideas?

> To work around this problem I created a map pid->time used which used
> getpid in the pre-NPTL-time and looked up the time in /proc/<pid>. As
> this doesn't work with NPTL, changed it to use the gettid syscall as I
> didn't find a saner way.

Changing it to gettid sounds like the right thing to do, but I also think
that you shouldn't _need_ to do things like this.

Linus