linux cpu usage code example
Example 1: linux cpu infos
# >>"lscpu"<< shows general information about your CPU:
# - name
# - frequency
# - architecture
# - etc.
lscpu
# If you were looking for the current CPU usage, try >>"top"<<
Example 2: linux check cpu usage
lscpu
# Or
cat /proc/cpuinfo
Example 3: get current cpu utilization in percentage linux
top -bn1 | grep "Cpu(s)" | \
sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
awk '{print 100 - $1"%"}'
Example 4: how to set cpu usage to 100% linux
$ sudo cpulimit --pid 17918 --limit 50
Process 17918 detected