How to programmatically query CPU load?

I’m using Jetpack 5.0.2 on Jetson AGX Orin Devkit. I need to collect CPU load / utilisation from a C program. On Jetson, I know I can use tegrastats from the terminal, or the built-in GUI. But is there a way to collect similar info programmatically in a C program?

I know for GPU, I can monitor /sys/devices/platform/gpu.0/load but I can’t find the relevant file for a given CPU, I’ve looked at the /sys/devices/system/cpu folder but can’t find anything related to CPU load.

Is there a document for me to find these path?

We don’t have the C program API, the only provide is the L4T doc: Tegrastats Utility — Jetson Linux
Developer Guide 34.1 documentation (

I don’t know the details, but programs like ps, xosview, and top (and my favorite, htop) tend to aggregate what they use from “/proc”. Note that most of those link to “”, although they might use their own algorithm to look at individual files in “/proc”.

An interesting tool is “strace”. For example, to see system calls from ps (mixed with actual ps output):
sudo strace ps 2>&1 | less

Within less search for “proc” via:
(then the “n” key for the next match, or “p” key for previous match)

strace can also be told to log its output (which avoids mixing with actual “other” command output). This is also useful on a program like tegrastats because tegrastats can’t be told to just output one line and quit (at least so far as I know), and strace puts out an enormous list of system calls (a C-like syntax). One can hit CTRL-c within tegrastats to stop it, and if you used less instead of a log file, then you’d lose the output (but a log remains). You can search that log for files it queries.

Note that in “/proc” there is a numeric subdirectory named after the PID of every process except 0 (the kernel itself is PID 0, and init is PID 1; all else spawns from PID 1, and is the beginning of “user space”; PID 0 is not listed because the processes in question are user space). Within each PID there is information used for CPU activity. Take a look at this strace:
sudo strace ps 2>&1 | egrep '(\/proc\/[0-9]+\/)'

There is no exact CPU stat which a program can query; it is an amalgamation of information on individual processes. The files in “/sys” which support a GPU load are specifically added by that GPU driver (which NVIDIA created). A CPU does not have a “driver” in the usual sense…this is the kernel itself, and is kernel space (PID 0).

1 Like


Thank you so much for the insights!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.