Copy Code code as follows:
#! /bin/sh
# filename killcpu.sh
If [$#!= 1]; Then
echo "USAGE: $ <CPUs>"
Exit 1;
Fi
For i in ' seq $ '
Todo
Echo-ne "
i=0;
While True
Todo
i=i+1;
Done "| /bin/sh &
pid_array[$i]=$!;
Done
For i in "${pid_array[@]}"; Todo
echo ' Kill ' $i ';
Done
Using the method is very simple, parameter 3 means consuming 3 CPU resources, after running, there will be a bunch of kill command to facilitate the kill process:
Copy Code code as follows:
[root@test02 ~]#./killcpu.sh 3
Kill 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.19
tasks:185 Total, 5 running, 180 sleeping, 0 stopped, 0 zombie
cpu0:100.0% us, 0.0% sy, 0.0% ni, 0.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
cpu1:0.0% us, 0.0% sy, 0.0% ni, 100.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
cpu2:100.0% us, 0.0% sy, 0.0% ni, 0.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
cpu3:100.0% us, 0.0% sy, 0.0% ni, 0.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
mem:8165004k Total, 8095880k used, 69124k free, 53672k buffers
swap:2031608k Total, 103548k used, 1928060k free, 6801364k cached