Re: How to find the CPU usage of a process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/18/06, Bernd Eckenfels <[email protected]> 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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux