Messages in this thread | | | Date | Sat, 18 Feb 2006 10:55:14 -0800 | From | "Ulrich Drepper" <> | Subject | Re: How to find the CPU usage of a process |
| |
On 2/18/06, Bernd Eckenfels <be-news06@lina.inka.de> wrote: > You can use the result wof wait3(2) if you are the parent: > [...]
That's after the fact. Programs which want to get the information while running can use the CPU clocks:
struct timespec ts; if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) != 0) fatal("cannot get CPU time"); /* result is in TS */
It's also possible to get a thread's CPU consumption. Use CLOCK_THREAD_CPUTIME_ID in that case.
All this works as it should ever since Roland's clock patches landed, in early 2.6 kernels. Before that the time returned did not discount the time the process wasn't scheduled. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |