Often I have to test Linux systems to see how do they work when they have an high CPU load.
To generate High CPU load (100%) I've written a small shell script and then I generalized it to work fine on multi core architectures.

The CPU consuming function uses dd to get data from the /dev/urandom device

and then uses gzip to make some CPU intensive job. Such a function is mono thread, so it generates 100% load on a single core. To generate 100% load on a multicore architecture, the script has to create multiple instances of the CPU consuming function. The script accept has input parameter the number of CPU consuming functions it has to launch..

shell1

The source code for the script is the following one:

#!/bin/bash
cpuConsumingFunc()
{
         dd if=/dev/urandom | bzip2 -9 >> /dev/null;
}
fulload()
{
    x=0
    while [ $x -lt $1 ]; do
        cpuConsumingFunc&
        let x=x+1 
    done
};
echo "----- Starting CPU load" 
fulload $1;
echo "Press enter to stop CPU load"
read;
echo "----- CPU load stopped"
killall dd


save the script as you like, since I have a lot of fantasy, I named it cpuLoad.sh. Then run 

$ chmod +x cpuLoad.sh

This makes the script executable.

then run the script issuing the command

$ ./cpuLoad.sh <number of CPU load functions>

Nothing more