lkml.org 
[lkml]   [2006]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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/

\
 
 \ /
  Last update: 2006-02-18 19:57    [W:1.929 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site