mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Linux

Reply
 
Thread Tools
Old 2022-03-13, 21:38   #1
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

22×383 Posts
Default CPU usage on Linux

I wrote small script to show me cpu usage, temperature of CPU , used memory, uptime...


what is my problem?


When I run mprime under linux then script show some percentage of usage (nearly every time 100%)

since it run on all cores

Quote:
echo
top -n 1 | awk 'NR>7 && $2=="root" { sum += $9 } END { print "CPU USAGE:" (sum/800)*100" %" }'
echo

Currently I run boinc clinet with 8 LLR2 task and CPU usage is zero?


Quote:
RYZEN 3700X
CURRENT DATE AND TIME
13-03-2022 22:36:38
TOTAL MEMORY = 7.78075 GB
CPU TEMPERATURE
+49.8°C
***** UP TIME *****
2 weeks, 3 days, 12 hours, 31 minute
CPU USAGE:0 %

Where is error in my script?
pepi37 is online now   Reply With Quote
Old 2022-03-13, 23:00   #2
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

101628 Posts
Default

Try sum*100/800 or simply sum/8.
paulunderwood is offline   Reply With Quote
Old 2022-03-14, 06:50   #3
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

5FC16 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Try sum*100/800 or simply sum/8.
Thanks, I will try it, but I asked why is cpu usage process dependent? When run mprime show correct value, but when I run llr2 and Boinc show zero usage?
pepi37 is online now   Reply With Quote
Old 2022-03-14, 07:33   #4
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

23·283 Posts
Default

Quote:
Originally Posted by pepi37 View Post
Thanks, I will try it, but I asked why is cpu usage process dependent? When run mprime show correct value, but when I run llr2 and Boinc show zero usage?
Maybe those other programs don't run as root?
retina is online now   Reply With Quote
Old 2022-03-14, 22:20   #5
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

145558 Posts
Default

Perhaps a more robust summation script would be this:

CORES=$(grep stepping /proc/cpuinfo | wc -l) ; awk "{ total+=\$1 } END { print total/$CORES }" <(ps -u $USER -o %cpu h)

If you wanted track just for particular programs then maybe this:

CORES=$(grep stepping /proc/cpuinfo | wc -l) ; awk "{ total+=\$1 } END { print total/$CORES }" <(ps -C mprime,boinc -o %cpu h)

Or for all processes:

CORES=$(grep stepping /proc/cpuinfo | wc -l) ; awk "{ total+=\$1 } END { print total/$CORES }" <(ps -o %cpu h)
retina is online now   Reply With Quote
Old 2022-03-15, 16:46   #6
chris2be8
 
chris2be8's Avatar
 
Sep 2009

22·587 Posts
Default

Or:
CORES=$(grep -c stepping /proc/cpuinfo)

Which is slightly faster, but I'd only run it once at the start of a script so speed wouldn't make much difference.
chris2be8 is offline   Reply With Quote
Old 2022-04-21, 06:03   #7
Mark Rose
 
Mark Rose's Avatar
 
"/X\(‘-‘)/X\"
Jan 2013

1011100010012 Posts
Default

Or CORES=$(nproc)
Mark Rose is offline   Reply With Quote
Old 2022-04-21, 06:08   #8
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

23·283 Posts
Thumbs up

Quote:
Originally Posted by Mark Rose View Post
Or CORES=$(nproc)
Yeah, better.

But also nproc --all to ensure you count all cores, not just those in the current process.
retina is online now   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Subsystem for Linux v2 gets real Linux kernel tServo Software 0 2019-05-07 16:59
GPU Usage Brain GPU Computing 9 2011-04-12 22:25
Usage of GMP-ECM ECMFreak Factoring 13 2007-07-20 17:34
max heap usage of Linux process prasanta Programming 1 2006-11-13 22:49
CPU usage Unregistered Software 6 2003-11-19 07:05

All times are UTC. The time now is 16:07.


Fri Jul 1 16:07:26 UTC 2022 up 78 days, 14:08, 0 users, load averages: 1.09, 1.54, 1.48

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔