How to create a CPU spike with a bash command
You can also do
dd if=/dev/zero of=/dev/null
To run more of those to put load on more cores, try to fork it:
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 the command in the curly brackets as many times as the number of threads you want to produce (here 4 threads).
Simple enter hit will stop it (just make sure no other dd is running on this user or you kill it too).
Bash: wait until CPU usage gets below a threshold
wait_for_cpu_usage()
{
current=$(mpstat 1 1 | awk '$12 ~ /[0-9.]+/ { print int(100 - $12 + 0.5) }')
while [[ "$current" -ge "$1" ]]; do
current=$(mpstat 1 1 | awk '$12 ~ /[0-9.]+/ { print int(100 - $12 + 0.5) }')
sleep 1
done
}
Notice it requires sysstat package installed.
Related Topics
How to Search Contents of Multiple PDF Files
Difference Between Shell and Environment Variables
Git Status Ignore Line Endings/Identical Files/Windows & Linux Environment/Dropbox/Meld
Maximum Number of Bash Arguments != Max Num Cp Arguments
Need to Remove the Count from the Output When Using "Uniq -C" Command
How to Make Mv Create the Directory to Be Moved to If It Doesn't Exist
Uevent Sent from Kernel to User Space (Udev)
Replace the First Line in a Text File by a String
How Is the Linux Kernel Tested
Does Linux Schedule a Process or a Thread
How Clear and Invalidate Arm V7 Processor Cache from User Mode on Linux 2.6.35
How to Edit /Etc/Sudoers from a Script
How to Attach a File Using Mail Command on Linux
How to Set Process Id in Linux for a Specific Program