[feat] posix scripts, vim, mutt, gpg, font
[dotfiles_afify.git] / .scripts / cpu.sh
blob4a124a31cbf486c185f1b58ef715096b79d4407f
1 #!/usr/bin/env bash
3 #==============================================================================
4 # Name : cpu
5 # GitHub : Afify
6 # Copyright : MIT
7 # Version : 0.1
8 # Description : print cpu percentage usage.
9 #==============================================================================
11 read cpu a b c previdle rest < /proc/stat
12 prevtotal=$((a+b+c+previdle))
13 sleep 0.5
14 read cpu a b c idle rest < /proc/stat
15 total=$((a+b+c+idle))
16 cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
17 echo -e "$cpu%"
19 # Get top 10 process usage
20 # ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10