CPU resources are consumed in an endless loop. If the server has multiple CPUs, you can select the number of CPU resources to be consumed:
#! /bin/sh # filename killcpu.shif [ $# != 1 ] ; then echo "USAGE: $0 <CPUs>" exit 1;fifor i in `seq $1`do echo -ne " i=0; while true do i=i+1; done" | /bin/sh & pid_array[$i]=$! ;donefor i in "${pid_array[@]}"; do echo 'kill ' $i ';';done
The usage is very simple. Parameter 3 indicates that three CPU resources are consumed. After running, there will be a bunch of kill commands to facilitate the kill process:
[root@test02 ~]# ./killcpu.sh 3kill 30104 ;kill 30106 ;kill 30108 ;[root@test02 ~]# top top - 15:27:31 up 264 days, 23:39, 4 users, load average: 0.86, 0.25, 0.19Tasks: 185 total, 5 running, 180 sleeping, 0 stopped, 0 zombieCpu0 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% siCpu1 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% siCpu2 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% siCpu3 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% siMem: 8165004k total, 8095880k used, 69124k free, 53672k buffersSwap: 2031608k total, 103548k used, 1928060k free, 6801364k cached