-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpuload
executable file
·66 lines (53 loc) · 1.01 KB
/
cpuload
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
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
set -o noclobber
usage() {
cat <<EOF
Usage: $0 [--help] [--jobs]
Increase CPU load.
Optional arguments:
--help, -h Show this help and exit
--jobs, -j Number of cores to use. Defaults to the total number of processors.
EOF
}
trap killgroup SIGINT
killgroup() {
echo "Done."
exit 0
}
worker() {
local _worker_id="$1"
# gzip --best --to-stdout /dev/urandom >/dev/null
# sha256sum /dev/zero
sha256sum /dev/urandom
}
cpuload() {
local num_jobs="$1"
echo "Generating CPU load with $num_jobs jobs..."
local id
for id in $(seq 1 "$num_jobs"); do
worker "$id" &
done
wait
}
main() {
local num_jobs
num_jobs="$(nproc)"
while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
usage
exit
;;
--jobs | -j)
num_jobs="$2"
shift
;;
esac
shift
done
cpuload "$num_jobs"
}
main "$@"