Take the 2-minute tour ×

I'm currently in the process of debugging a Cacti installation and want to create CPU load to debug my CPU utilization graphs.

I tried to simply run cat /dev/zero > /dev/null, which works great, but only utilizes 1 core:
enter image description here

Could someone suggest a better approach maybe?

Related: How can I produce high CPU load on Windows?

share|improve this question
is it possible to run multiple instances of cat simultaneously? –  Nate Koppenhaver Jun 30 '12 at 17:16
@NateKoppenhaver: Yes, that seems to be possible when wrapping them in screen sessions. But I would prefer a more sophisticated solution if possible. –  Oliver Salzburg Jun 30 '12 at 17:18
Heh, I always used cat /dev/random > /dev/null. Guess /dev/zero works too. :-) –  oKtosiTe Jul 1 '12 at 7:25
@oKtosiTe cat /dev/random has the side effect of depleting the entropy in /dev/random. There are times you need to conserve entropy, I wouldn't have this as my go to CPU hog. –  Rich Homolka Jul 25 '12 at 21:41
add comment

8 Answers

up vote 38 down vote accepted

Try stress It's pretty much an equivalent of the Windows consume.exe:

oliver$ ./stress --cpu 3
stress: info: [18472] dispatching hogs: 3 cpu, 0 io, 0 vm, 0 hdd
share|improve this answer
on ubuntu, you can install with sudo apt-get install stress –  ben Apr 25 '13 at 17:50
on debian wheezy too. –  enapupe Oct 15 '13 at 1:42
add comment

This will load your four cores at 100%:

for i in 1 2 3 4; do while : ; do : ; done &  done

Edit: How it works is quite simple, it starts four endless loops. Each of them is repeating the null instruction (:). Each loop is able to load a CPU core at 100%.

share|improve this answer
How this do? Can you explain, please? –  mmdemirbas Jul 4 '12 at 13:08
@mmdemirbas: explanation added. –  jlliagre Jul 4 '12 at 13:42
Thanks, but & causes a command to run in a separate thread or separate core? I am confused. –  mmdemirbas Jul 4 '12 at 14:23
@mmdemirbas: The ampersand causes the command to run as a separate process. The scheduler is then dispatching all the active processes to all available cores . –  jlliagre Jul 5 '12 at 1:54
Thank you @jlliagre. –  mmdemirbas Jul 5 '12 at 6:33
show 1 more comment

Compile the Linux kernel or GCC from source with:

make -j N

Where N is the number or cores + 1. You can do it in a loop in a bash script (make clean; make -j N) if you want a continuous load.

share|improve this answer
Actually, specifying -j without a number is the most efficient way to bring the system down. I had a load of 80 once, not very usable system. –  ott-- Jul 1 '12 at 14:17
add comment

I made a simple python script which does the same. You can control the number of cpu cores you want to load. The good thing about this is that it won't consume any other resource besides the cpu. (I think mark johnson's idea would consume a lot of I/O resources, which is undesired here.)

from multiprocessing import Pool

def f(x):
    # Put any cpu (only) consuming operation here. I have given 1 below -
    while True:
        x * x

# decide how many cpus you need to load with.
no_of_cpu_to_be_consumed = 3

p = Pool(processes=no_of_cpu_to_be_consumed)
p.map(f, range(no_of_cpu_to_be_consumed))

Just run this script from the terminal $ python temp1.py. You need to kill the script when you are done.

Here, is my cpu consumption output when I load 3 of my cores.

Script temp1.py creates three processes (PIDs - 9377, 9378, 9379) which load 3 of my cores

share|improve this answer
What program do you used to display CPU usage like this? It reminds me of top, but I don't recall the CPU 'charts'. –  jftuga Jul 1 '12 at 1:13
@jftuga probably htop, top's prettier brother. –  BoppreH Jul 1 '12 at 3:38
yes its htop. Best real time, colorful interactive process viewer for linux - htop.sourceforge.net –  Guanidene Jul 2 '12 at 17:12
Wasn't paying attention and ran this on a Windows box. Very bad things... –  Derrick Boudwin Feb 7 '13 at 17:43
add comment

I usually take the cpuburn suite:

sudo apt-get install cpuburn
for i in {1..4}; do burnK7 & done

Replace 4 with the number of cores / HT-threads you have or want to stress.

Note: This stresses as much chip area as possible at the same time, it's programmed to generate maximum power dissipation. I had to write this post a second time, somehow my machine didn't like it :-(

You could also do cpuburn in sequences:

burnP6 & burnP6 & burnP6 & burnP6 & 
[1] 28520
[2] 28521
[3] 28522
[4] 28523

And when you want to stop them:

killall burnP6

You could also multiply burnP6 & to match the number of CPU cores on your system.

share|improve this answer
add comment

A simple command line does it too:

x="x" ; while : ; do x=$x$x ; echo -n "." ; done
share|improve this answer
This would be simpler: while : ; do : ; done –  jlliagre Jul 1 '12 at 6:30
@jlliagre Yours wön't go above loadavg 1. –  ott-- Jul 1 '12 at 11:06
Your loop isn't primarily loading the CPU but more filling the memory. It will eventually crash with an out of memory error. –  jlliagre Jul 1 '12 at 12:31
@jlliagre Mine fills memory and swap (if present), thus producing a load of 3 before it killed because it runs out of memory. –  ott-- Jul 1 '12 at 14:14
That's the problem. You aren't answering the question asked which is how to produce a high CPU load on a server. Your script is quickly making a system unresponsive and then crashes. There are much more reliable ways to get a loadavg of 3. eg: for i in 1 2 3; do while : ; do : ; done & ; done –  jlliagre Jul 1 '12 at 14:52
add comment

You can run that command as many times as you want, and it will take up a different core each time:

$ for i in `seq 1 $CORES`; do cat /dev/zero > /dev/null &
> done
[1] 8388
share|improve this answer
Wouldn't that make terminating the processes a bit of a hassle? –  oKtosiTe Jul 1 '12 at 7:26
killall cat should do it. –  Christian Mann Jul 1 '12 at 21:00
Depending on whether you have other cat processes running (I usually do). –  oKtosiTe Jul 2 '12 at 13:36
add comment

pretty simple and scientific solution:


share|improve this answer
add comment

Your Answer


