/ linux

How to stress-test a CPU on a Linux server

In some cases, you may want to voluntarily stress-test the CPU of a Linux server to see what happens (monitoring stuff for example).


First, create a file on your hard drive with the following command:

dd if=/dev/urandom of=testfile count=20 bs=1024k

Next, create a shell script with a md5sum loop as below, and named it "stress_cpu":



while [ 1 ]
  md5sum testfile
  i=`expr $i + 1`
  echo "Iteration: $i"

Make the script executable :

chmod +x stress_cpu

Then, you just need to execute it and your CPU load will increase instantly.


Ctrl-C will end it, as always.