Last active
May 12, 2024 17:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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