Skip to content

Instantly share code, notes, and snippets.

@singiamtel
Last active May 12, 2024 17:11
Show Gist options
  • Save singiamtel/111f5f65786dfcbe38262cf358aec048 to your computer and use it in GitHub Desktop.
Save singiamtel/111f5f65786dfcbe38262cf358aec048 to your computer and use it in GitHub Desktop.
Bash script for stress testing a system by spawning multiple CPU-intensive processes. The script includes a signal handler to clean up any child processes before exiting. Useful for stress testing and space heating purposes
#!/bin/bash
cleanup() {
# Kill any child processes
echo "Cleaning up child processes..."
pkill -P $$
# Exit the script
exit 0
}
cpu_num=$1
if [ $# -ne 1 ]; then
cpu_num=$(nproc)
fi
# Register the cleanup function to run on SIGINT and SIGTERM signals
trap cleanup SIGINT SIGTERM
for i in `seq $cpu_num`
do
echo "cpu$i"
while true
do
j=1
done &
done
# Wait for child processes to complete
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment