CPU Load Script
Description
The following scripts can be used to put load on one or many CPU/Cores of a Unix machine. Details of their use can be found in the headers of the scripts. The running scripts can be stopped using the pkill as detailed below.
pkill LoadScript.ksh
RunLoadScript.ksh
#!/usr/bin/ksh
#
# Name: LoadScript.ksh
#
# Description: Generates CPU Load on a Unix Machine. This will load a CPU for a given number of loop cycles
# as defined by the variable "num" before sleeping for a given number of seconds as determined
# by the sleep value. The script will continue this load, sleep loop until killed.
# Alternatively, if the sleep parameter is hashed out the script will stress a CPU to the max
# continuously until killed. This script can be very useful in a testing environment to
# see how a machine/application behaves under load.
#
# Usage: Called by RunLoadScript.ksh
#
#
#
# Create an infinite outer Loop
#
while :
do
#
# Set the number of loop cycles
#
integer num=200000
#
# Create an inner loop and stress the CPU for the defined number of loop cycles.
#
while (( num ))
do
(( num = num -1 ))
:
done
#
# Set a sleep value to give the CPU a rest or hash out to stress the CPU to the max.
#
sleep 5
#
# End Outer Loop
#
done
RunLoadScript.ksh
#!/usr/bin/ksh
#
# Name: RunLoadScript.ksh
#
# Description: Submits X number of LoadScripts.kah as defined by variable num. Variable num should be set to the number of CPUs/Cores you wish to
# load. Note: The script will swap from CPU to CPU.
#
# Usage: Used to submit LoadScript.ksh. Terminate all submitted processes using pkill <procid>
#
#
#
# Set num to the number of CPUs/Cores.
#
integer num=64
#
# Submit a LoadScript for each CPU/Core.
#
while (( num ))
do
./LoadScript.ksh&
(( num = num -1 ))
done