You are not logged in.
Hi.
Up until this point, I've been using `mpstat 1` in my panel script to get cpu usage per second. However, today I rewrote the whole code to use less loops, so that there is one loop that every second updates certain variables (one of those is the cpu load). Now, since `mpstat 1 1` takes one second to execute, I would have to disown the function assigning the cpu load value to the cpu variable, but then a new environment is created, so that does not work. I need a new way of getting the cpu load, that only takes a moment to run. Does anyone know a good solution to this? Since it will run every second all my uptime, I want it to use as few resources as possible, as greedy as that might sound.
I have been considering using /proc/stat, but I don't know what they different words in the output means:
cpu 406642 929 196454 11146198 4428 1 999 0 0 0
This is how my code is (intended to) work right now:
while true; do
cpu &
clock
temperatures
done
Where all of cpu, clock and temperatures are functions. It doesn't help if `cpu &` is placed in the end, because later in the loop, I update the text sent to bar, and I don't want a delay to that.
Edit: I found a temporary solution using `mpstat 1`, piping it to the FIFO that my panel script reads from, and when the panel script reads a cpu entry, it sets its own cpu variable to the value it received from the fifo, and then it calls `continue`, so it will not update the text sent to bar. Every second, the text sent to bar will naturally contain the updated cpu load value. (sorry if I'm explaining it bad.. it's not that cruicial to understand this anyway). I'm mostly wondering about the meaing of /proc/stat atm.
Last edited by Ploppz (2014-11-10 00:38:06)
Offline
Offline