/
cpuburn-m
executable file
·102 lines (87 loc) · 2.7 KB
/
cpuburn-m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
#
# Wrapper for CPUburn-in
# ======================
#
# It automatically detects the number of CPUs to stress them all at the same
# time. This requires to run multiple instances of cpuburn-in, because 1
# process can only be executed on 1 CPU.
#
#
# Licensed under the GNU General Public License, version 2 or later.
# This program comes with ABSOLUTELY NO WARRANTY. See the GNU GPL for details:
# <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
#
# Written by Gert Hulselmans and Explorer.
# Last updated on 1 August 2014.
set -m
CPUS=`awk '/^processor/ {CPU=$3}; END {print CPU+1}' /proc/cpuinfo`
CHLD_COUNT=0
sigchld_handler () {
trap - 17
CHLD_COUNT=$(($CHLD_COUNT+1))
if [ "$CHLD_COUNT" -ge "$instances" ]; then
trap - 1 2 3 15
exit 0
fi
trap 'sigchld_handler' 17
read -s -n1 REPLY
}
# This script expects that 'read' be interrupted by a signal. Notably bash
# doesn't do this.
if [ "X$BASH" != X ]; then
echo "Don't run this script in bash." >&2
exit 1
fi
printf "\033[0;32mCPU Burn-in v1.00:\n"
printf "==================\033[0m\n\n"
case "$1" in
--help | -h)
cat << HELP
Usage: $0 [TIME]
Run cpuburn-in and stress test for TIME minutes.
If TIME is not specified, run cpuburn-in for 10080 minutes (= 7 days).
To specify how many instances of cpuburn-in will be run, export the 'instances'
shell variable before running this script. e.g. 'export instances=1'
HELP
exit 0
;;
esac
# $days, $hours, and $minutes are environment variables as well as boot
# parameters.
if [ "X$1" != X ]; then
TIME="$1"
elif [ "X$days" != X ]; then
TIME=$(($days*24*60))
elif [ "X$hours" != X ]; then
TIME=$(($hours*60))
elif [ "X$minutes" != X ]; then
TIME="$minutes"
else
TIME=10080
fi
if [ "$instances" -gt 0 ] 2>/dev/null; then
:
else
echo "Detecting the number of CPUs: $CPUS detected."
instances="$CPUS"
fi
if [ "$instances" -eq 1 ]; then
echo "Running 1 instance of cpuburn-in ('/opt/cpuburn-in/cpuburn-in $TIME')."
exec /opt/cpuburn-in/cpuburn-in $TIME
else
echo "$instances instances of cpuburn-in will be run in the background."
printf "\033[01;31mTo stop cpuburn-in, press any key.\033[0m\n"
PID_LIST=""
trap 'trap - 17; kill $PID_LIST; wait; trap - 1 2 3 15; exit 0' 1 2 3 15
for i in `seq 1 $instances`; do
echo "cpuburn-m: Starting instance $i of cpuburn-in ('/opt/cpuburn-in/cpuburn-in $TIME &')."
/opt/cpuburn-in/cpuburn-in $TIME &
PID_LIST="$PID_LIST $!"
done
trap 'sigchld_handler' 17
# This 'read' may be interrupted by a SIGCHLD.
read -s -n1 REPLY
echo "cpuburn-m: Terminating."
trap - 17; kill $PID_LIST; wait; trap - 1 2 3 15; exit 0
fi