Skip to content

Instantly share code, notes, and snippets.

@yalla
Created August 9, 2011 12:29
Show Gist options
  • Save yalla/1133915 to your computer and use it in GitHub Desktop.
Save yalla/1133915 to your computer and use it in GitHub Desktop.
Small CPU load testing script which uses openssl and is kinda bulletproof on Linux.
#!/bin/bash
NUMCPUS=`grep -c processor /proc/cpuinfo`
if [ -z "$1" ] ; then
NUMINSTANCES=2
else
echo $1 | grep "^[0-9]*$" >/dev/null
if [ "$?" -ne 0 ] ; then
echo Argument $1 is not a number. Aborting.
exit 1
else
if [ "$1" -gt "$NUMCPUS" ] ; then
echo Want to start more instances than CPUs available? Very
echo brave. Type yes to continue.
read answer
if [ "$answer" != "yes" ] ; then
echo Wise answer, my young padawan. Aborting.
exit 2
fi
echo Good luck and have a lot of fun...
fi
NUMINSTANCES=$1
fi
fi
waitlist=""
for ((i=1; i<=$NUMINSTANCES; i++)) ; do
echo Starting instance $i...
openssl speed &
instances[$i]=$!
waitlist="${instances[$i]} $waitlist"
done
trap "kill $waitlist" SIGINT SIGTERM
wait $waitlist
echo All processes finished.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment