NUKI

These for a long time “sleeping boxes” they bother my health 🙂 In particular, they work, work and at some point the receiver crashes and requires a restart of the CAM module. In my case I use newcs and mgcamd to decode the programs and when I crashed a program the mgcamd process was overloaded developing values ​​of the order of 80-90% borrowing CPU power 🙂 Clearly there was already a disease there was a symptom and I only needed medicine 😉 nice but my little ones 500s don't have a large capacity of commands for example ps there is no u argument top there is no -p etc. we really hate busybox 😆 Enough nonsense let me get to the bottom of it 🙂 All the necessary information is contained in the folder /proc after a lot of reading back and forth and after help from my good friend ShadowX without which I would not have been able to come to the following wonderful script cry 🙂 Also my friend Nathariel who put up with my buzz all the time 😉 hah typically for me i start explaining something i start second third and fifth 🙂 hahahaha So enough nonsense but let me brag about how cool a programmer I am съм

The most important construction in the script is

# Get usage cpu time
cputime=`cat /proc/uptime | awk '{print $1}' | sed 's/\.//'`
# Get process usage cpu time
proctime=`cat /proc/${procpid}/stat | awk '{t = $14 + $15;print t}'`
# wait 5 seconds
sleep 5
# get usage cpu time, again
cputime2=`cat /proc/uptime | awk '{print $1}' | sed 's/\.//'`
# get process usage cpu time, again
proctime2=`cat /proc/$procpid/stat | awk '{t = $14 + $15;print t}'`
# calculate process usage cpu time over total usage cpu time as percentage
cpu=$((($proctime2-$proctime)*100/($cputime2-$cputime)))
# limit exceed check
echo CPU usage for PID $procpid is $cpu
if [ $cpu -gt $MAX ];
then
reboot
fi

in general I have described it well with comments as a good child 😉 Generally this is the heart of the script takes a value from / proc / process id / stat and then reads the value 5 seconds later. The calculation formula is crystal clear to understand and a sophomore will solve it easily. Something very important to emphasize is, that the script uses ash which is quite unpleasantly shredded if you are used to all the lignans of bash 😉 In the page of the script I have described in detail the technology of work and the logic of use. I will enjoy the reviews recommendations and bug report, because one head is not enough 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti SPAM *