Get Current Process CPU Usage Linux C

10,355

You can use the times system call, which gives the time spent by the CPU on a given process. Try this tutorial, Linux process execution time.

Share:
10,355
Mike Telson
Author by

Mike Telson

Updated on June 04, 2022

Comments

  • Mike Telson
    Mike Telson over 1 year

    I'd like to get the specific CPU Usage of a process under Linux in C++. However, apart from reading

    /proc/stat
    

    I don't know how to do that.

    If I read this file, then I don't know how I can't get the CPU usage of my current process when I launch the program ...

    I want to get the CPU usage of the program I'm running, do you have any clue on how to do it ? I've seen complex solution on the site and I haven't understood them all ... I just need a direction.

    It seems my /proc/pid/stat file isn't changing after sleep(2), is that normal ?