Created
October 12, 2023 06:04
-
-
Save driversti/ec81c4abf4547f6e00dd54dce79de46c to your computer and use it in GitHub Desktop.
Load Oracle instance
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 | |
# start_cpu_stress.sh | |
# Calculate the desired CPU limit based on the total number of cores | |
total_cores=1 | |
desired_load_percentage=90 | |
cpu_limit=$(awk -v cores="$total_cores" -v perc="$desired_load_percentage" 'BEGIN { printf "%d", cores * perc }') | |
echo "CPU limit: $cpu_limit%" | |
# Run stress in the background | |
stress --cpu "$total_cores" & | |
stress_pid=$! | |
# Apply the CPU limit to the stress process | |
cpulimit -p "$stress_pid" -l "$cpu_limit" & | |
cpulimit_pid=$! | |
# Save the PIDs to a file | |
echo "stress_pid=$stress_pid" > stress_cpu_pids | |
echo "cpulimit_pid=$cpulimit_pid" >> stress_cpu_pids |
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 | |
# stop_cpu_stress.sh | |
# Kill the stress and cpulimit processes | |
pkill -9 stress | |
pkill -9 cpulimit | |
# Remove the PIDs file if it exists | |
if [ -f stress_cpu_pids ]; then | |
rm stress_cpu_pids | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment