One way command to achieve a CPU usage 100%

for i in `seq 1 $(cat /proc/cpuinfo |grep “physical id” |wc -l)`; do dd if=/dev/zero of=/dev/null & done

Description:

cat /proc/cpuinfo |grep “physical id” | wc- l The number of CPUs can be obtained,   we will express it as N.

seq 1 N is used to generate numbers between 1 and N

for i in `seq 1 N`; is to execute commands in a loop, from 1 to N

dd if=/dev/zero of=/dev/null execute dd command,   output to /dev/null , Actually only occupies the CPU, “no IO operation.

Since N (N is the number of CPUs) dd commands are executed continuously, and the utilization rate is 100%, the scheduler will schedule Each dd command is processed on a different CPU.

Eventually realize 100% of all CPU occupancy rate

In addition, the end of the above program can be used:

1. Press ctrl + C after fg (because the command is executed in the background)

2. pkill -9 dd

Leave a Comment

Your email address will not be published.