'Getting time of thread owned by another process

I need to monitor the time of the threads. To do this, I need to get the threads' clock IDs. Since I need to keep track of other processes' threads, I don't have a pthread_t identifier and can't use pthread_getcpuclockid. I looked at the implementation of pthread_getcpuclockid and implemented a similar function in my program (it uses the glibc internal macro MAKE_THREAD_CPUCLOCK). And I use clock_gettime to get the thread times. Everything works fine when I'm tracking my own child threads. But if I try to track another process's thread, clock_gettime returns -EINVAL. The clock ID is correct (I checked it inside the program being monitored). Is there way to watch other processes' threads times?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source