Skip to content

Instantly share code, notes, and snippets.

@Narrator
Created December 13, 2024 02:20
Show Gist options
  • Save Narrator/b1ded84be2ebb1ceb7eb55542a1a5879 to your computer and use it in GitHub Desktop.
Save Narrator/b1ded84be2ebb1ceb7eb55542a1a5879 to your computer and use it in GitHub Desktop.
#!/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