On 14-08-21, Jeremie Courreges-Anglas wrote: > On Sat, Aug 14 2021, Baptiste Jonglez <bapti...@bitsofnetworks.org> wrote: > > Hello, > > Hi Baptiste, long time no see. :)
Hi jca, indeed, good to talk to you :) Sorry for the late reply. > > I would like to determine the CPU usage of a process on a "real-time" > > basis. That is, every few seconds (sampling period), I would like to > > compute its average CPU usage in the previous period. > > Looks like a job for getrusage(2) or the CLOCK_PROCESS_CPUTIME_ID clock > supported by clock_gettime(2). Thanks for the pointer. It seems getrusage() and clock_gettime() apply only to the current process, while I'm more interested in other processes, like top. That is, I think the right interface to use is kvm_getprocs(). Besides, getrusage() seems to also use p_{u,s,i}ticks, so it would probably also suffer from the delayed updates of these fields; that being said, I haven't tested. Regards, Baptiste
signature.asc
Description: PGP signature