Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Is there a better method of testing/maxing-out system resources under load?

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
@oKtosiTe What Rich Homolka said is right, but it's not just that it's a bad thing to do, it's also useless because it'll block almost immediately and stop consuming cpu. – Luc Jul 22 '14 at 18:11

12 Answers 12

up vote 100 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
On Fedora, sudo yum install stress – Christopher Markieta Nov 13 '14 at 22:15
Arch: sudo pacman -S stress – das_j Feb 19 '15 at 19:44
brew install stress on OS X – Christian Long Jul 16 '15 at 14:15

No need to install any extra package, your good old shell is able to do it alone.

This one-liner will load your four cores at 100%:

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

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%.

If you use bash, ksh93 and other shells supporting ranges, (i.e. not dash or older ksh), you can use this non portable syntax:

for i in {1..4}; do ...

Replace 4 with the number of CPUs you'd like to load if different from 4.

Assuming you had no background job already running when you launched one of these loops, you can stop the load generation with that command:

for i in 1 2 3 4; do kill %$i; done

Answering @underscore_d's comment, here is an enhanced version that simplify a lot stopping the load and that also allow specifying a timeout (default 60 seconds.) A Control-C will kill all the runaway loops too. This shell function works at least under bash and ksh.

# Usage: lc [number_of_cpus_to_load [number_of_seconds] ]
lc() {
    echo loading $cpus CPUs for $seconds seconds
    trap 'for p in $pids; do kill $p; done' 0
    for ((i=0;i<cpus;i++)); do while : ; do : ; done & pids="$pids $!"; done
    sleep $seconds
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
@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
ehh, it works, but if the system began to get too overloaded and the user needed to stop the stress instantly, stress or something like it is much easier to kill via ctrl+c, rather than having to type a kill command or highlight 8 things in a task manager - if you can! – underscore_d Oct 30 '15 at 20:27
Great, it seems to cover everything now, +1 for the updates! – underscore_d Oct 31 '15 at 10:03

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
@ott Specifying -j without a number is a bad idea idea to stress the CPU, it will stress your RAM instead. – Teresa e Junior Mar 28 '15 at 17:44

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), range(no_of_cpu_to_be_consumed))

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

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

Script 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 - – Pushpak Dagade Jul 2 '12 at 17:12
Wasn't paying attention and ran this on a Windows box. Very bad things... – Derrick Feb 7 '13 at 17:43

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

I've been developing stress-ng, an updated stress tool that can stress a wide range of aspects of a Linux system. For more information, see

share|improve this answer
Please read How do I recommend software for some tips as to how you should go about recommending software. At the very least you should provide more than just/at least a link, for example some additional information about the software itself, and how it can be used to solve the problem in the question. – DavidPostill Sep 6 '15 at 20:33

Start two

sha1sum /dev/zero &

commands for every core in your system.

To stop

killall sha1sum


kill sha1sum
share|improve this answer

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

pretty simple and scientific solution:

share|improve this answer

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

You can use:

fulload() { dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null & }; fulload; read; killall dd

repeat "dd if=/dev/zero of=/dev/null" for your cpu cores. Hit any key to stop test.

share|improve this answer

I combined both +jlliagre and +ecabuk.

lc() {
    nowMs=$(date +%s)
        echo "[$(date)] loading $cpus CPUs for $seconds seconds"
        echo "[$(date)] Expected completion: [$(date --date=@$(expr $nowMs + $seconds))]"
        trap 'for p in $pids; do kill $p; done' 0
        for ((i=0;i<cpus;i++)); do
            sha1sum /dev/zero &
            pids="$pids $!";
        sleep $seconds
    echo "[$(date)] Done"

lc $@
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .