Created
December 13, 2024 02:20
-
-
Save Narrator/b1ded84be2ebb1ceb7eb55542a1a5879 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Get the number of CPU cores | |
NUM_CORES=$(nproc) | |
# Function to perform CPU-intensive calculations | |
cpu_stress() { | |
echo "Starting task on process $$" | |
start_time=$(date +%s.%N) | |
echo "scale=5000; a(1)*4" | bc -l > /dev/null | |
end_time=$(date +%s.%N) | |
duration=$(echo "$end_time - $start_time" | bc) | |
echo "Task on process $$ completed in $duration seconds" | |
} | |
# Launch a CPU-intensive process for each core | |
for ((i=0; i<NUM_CORES; i++)); do | |
cpu_stress & | |
done | |
# Wait for all tasks to complete | |
wait | |
# Notify user of completion | |
echo "All tasks completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment