如何让Linux 机器CPU使用率变高
一、实现
1、单行命令搞定
for i in `seq 1 $(cat /proc/cpuinfo |grep "physical id" |wc -l)`; do dd if=/dev/zero of=/dev/null & done
2、脚本方法
makeLoveCPU.sh
for i in `seq 1 $(cat /proc/cpuinfo |grep "physical id" |wc -l)`; do dd if=/dev/zero of=/dev/null & done
highCPU.sh
while true; do sh makeLoveCPU.sh $1 ; sleep 2; done
二、查看
可以使用top命令查看效果,预计效果如下所示:
top - 18:19:48 up 14 days, 3:48, 3 users, load average: 0.31, 0.43, 0.46
Tasks: 121 total, 3 running, 118 sleeping, 0 stopped, 0 zombie
%Cpu(s): 21.5 us, 78.1 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.3 si, 0.0 st
KiB Mem : 1883884 total, 129612 free, 1266472 used, 487800 buff/cache
KiB Swap: 2097148 total, 2064212 free, 32936 used. 420084 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17133 root 20 0 107948 612 516 R 99.0 0.0 0:08.38 dd
1806 cpic 20 0 4022952 1.125g 12148 S 1.0 62.6 148:11.10 java
401 root 20 0 0 0 0 S 0.3 0.0 6:07.16 xfsaild/dm-0
1 root 20 0 129124 4196 2180 S 0.0 0.2 0:20.00 systemd
三、关闭
可以通过kill -9 进行恢复CPU的正常使用情况。