#!/usr/bin/env bash # Keep some cores busy, standing in for heat and work competing with the program # (a hot afternoon, the modem, something else running). # # tools/thermal-sim/heat-load.sh 2 600 # 2 cores flat out for 10 minutes # # Uses stress-ng when installed; otherwise one busy shell loop per core. Ctrl-C # stops it early. Needs no root. set -euo pipefail [[ $# -eq 2 && $1 =~ ^[0-9]+$ && $2 =~ ^[0-9]+$ ]] || { echo "usage: $0 " >&2; exit 2; } cores=$1 secs=$2 if command -v stress-ng >/dev/null; then exec stress-ng --cpu "$cores" --timeout "${secs}s" --metrics-brief fi echo "stress-ng not found; using $cores busy loop(s) for $secs s" pids=() trap 'kill "${pids[@]}" 2>/dev/null' EXIT INT TERM for _ in $(seq "$cores"); do ( end=$((SECONDS + secs)); while (( SECONDS < end )); do :; done ) & pids+=($!) done wait