I have a shop of video courses. How to calculate the CPU load when viewing video (web-server on linux)?
You are asking for a kernel-internal value, so you won't have to compute anything, you just will query the kernel for that value.
Interactively you can use the top
command, as Daniel stated in his comment.
Programmatically, top
will be cumbersome. Instead, you can use uptime
as a high level tool for this. Use uptime | { IFS=\\ , read abcdefghijklm; echo "$j"; }
uptime | { IFS=\\ , read abcdefghijklm; echo "$j"; }
uptime | { IFS=\\ , read abcdefghijklm; echo "$j"; }
to only get the current load.
A little more lower level would be to use the proc file system. The file /proc/loadavg
provides the information about the load. You can use cut -d' ' -f 1 /proc/loadavg
to only get the current load.
For the smoothed-out average values of the load (there typically are given three values, the first is the current load, the two others are averages over long time periods), use $k
or $l
instead of $j
in the uptime
solution, and use -f 2
or -f 3
in the proc file system solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.