[英]Understanding CPU usage in linux using “top” command for VLC usage
[英]Calculate CPU usage from top command in linux
我使用類似的腳本已經有一段時間沒有問題了:
top -bn2 | grep Cpu | tail -n1 | sed -e 's/.*, *\([0-9.]*\)%* id.*/\1/' | awk '{print 100-$1}'
該腳本從頂部 output 中獲取“空閑”時間,並將其從 100% 中扣除以獲得 CPU 使用率。
您調用腳本的循環周期不應快於腳本完成所需的時間。 否則,您可能會得到多個 'top' 並行運行。 這主要取決於您系統上的“頂部”默認延遲,在我的系統上,它大約是 5 秒,但您可以使用 -d 開關進行設置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.