On my Raspberry pi 3, I have a Python script that opens at startup in the background. In the script there is a function that acquires the percentage of CPU used.
The function is as follows:
`def getCPUuse():
return(str(os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))`
If I run the program manually the function returns the value to me correctly, instead if the program is loaded at the start in the background the function does not return any value to me.
I searched everywhere, but I can't understand why.
Can someone help me?
Thanks
PS I don't want to use the psutil library!