A Quick CPU Intensive Script for Testing Purposes with md5sum

If you’re needing to create some sort of CPU stress test script on the fly with minimal resources on a Linux box, a simple md5sum loop comes in handy. Even with ‘watered-down’ versions of a Linux filesystem (ie. busybox) generally have at least the capabilities of running a loop and have the md5sum tool compiled and ready to use. A quick rundown on how to set one up is outlined below.

First, create a relatively large file (as large as you can make one without being overkill):

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

Second, create a script (I named it stress_cpu, but you can call it what you want) with the following contents:



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

Save the file and then give it executable permissions:

chmod +x stress_cpu

Finally, run it:


You may notice when running this script that the initial md5sum test takes about 10 seconds longer than any subsequent tests. This is due to the way md5sum works and how things are written to cache for faster access. If you don’t want anything to be cached for good measure, and you have /proc mounted with the /proc/sys/vm/drop_caches file, then you can use the command sync; echo 1 > /proc/sys/vm/drop_caches immediately following the md5sum command in the script. See the proc man page for more information.

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 3 Comments So Far

  • Rob Desbois
    April 15th, 2011 at 6:43 am

    Hi Derek, just came across your post searching for simple stress-testing techniques. A simpler one I’ve been using recently involves just dd, plus nice to ensure it gets as much CPU time as it can.
    > nice -n -20 dd if=/dev/zero of=/dev/null bs=1024k

    Pretty intensive…I guess if you wanted an even more intensive test, you could create a real-time scheduled program (sched_setscheduler(2)), but that could be a tad overkill 😉

  • muzzol
    December 2nd, 2011 at 6:54 am

    yes > /dev/null

Who Linked To This Post?

  1. CPU Stress Test Menggunakan Script MD5SUM | LifeBit.me

Share your thoughts, leave a comment!