When trying to stress test a CPU in a Linux environment, I think the easiest way is yes> / dev / null
.
However, this command has a weakness, and when the number of CPU cores is 2 or more, after executing multiple processes at the same time, the kill command will forcibly stop the process. [Linux] How to easily apply CPU load without using stress command
Therefore, the ʻopenssl` command introduced in I tried to summarize how to easily apply CPU load on Linux Using it, I made a script that can execute the stress test of the CPU considering the number of logical cores (number of threads) of the CPU.
#!/bin/bash
function usage {
cat <<EOS
$(basename ${0}) is a cpu stress test tool for multi-core processor.
Usage:
$(basename ${0}) [<options>]
Options:
-n using n cores in stress test. default is `grep processor /proc/cpuinfo | wc -l`.
EOS
}
CPU_THREADS=`grep processor /proc/cpuinfo | wc -l`
while getopts n:h OPT
do
case $OPT in
"n" ) CPU_THREADS="$OPTARG"
;;
"h" ) usage;
exit 0
;;
esac
done
echo "using "$CPU_THREADS" cores in stress test."
openssl speed -multi $CPU_THREADS > /dev/null 2>&1
-h
and -n
.-h
option to see a description of the command options.-n
option, but if you do not specify anything, use all the number of logical cores (number of threads) of the CPU assigned to this OS. And run a stress test.Command options
[root@akagi ~]# ./cpu_stress_test.sh -h
cpu_stress_test.sh is a cpu stress test tool for multi-core processor.
Usage:
cpu_stress_test.sh [<options>]
Options:
-n using n cores in stress test. default is 8.
Run CPU stress test
[root@akagi ~]# ./cpu_stress_test.sh -n 2
using 2 cores in stress test.
Recommended Posts