- timeout 10 top
- for i in $(seq 4); do (timeout 10 yes > /dev/null &); done
- for i in $(seq `grep -c ^proc /proc/cpuinfo`); do (t=$((10 + RANDOM%10)) && echo "Run:$i timeout $t seconds" && timeout $t yes > /dev/null &); done
第2個指令是說,產生跟邏輯核心一樣多的工作,每個都跑10~20秒左右
最後再搭配《Linux上看CPU型號與資訊》,寫一個可以根據實體核心數目燒CPU的Bash script(可以取名為burnCPU.sh),而且還可以決定要燒幾秒鐘:
- ./burnCPU.sh #燒機10秒鐘
- ./burnCPU.sh 60 #燒機一分鐘
- ./burnCPU.sh 86400 #燒機一天
#!/bin/sh
## 1. Setup the timeout ,default is 10 seconds
if [[ $# -eq 0 ]]; then
TOUT=10
else
TOUT=$1
fi
## 2. Determine the number of physical cores
# If there is not hyperthreading ($ht == 0)
# the number of physical cores equal to the logical cores (pcores = lcores)
# Otherwise (hyperthreading is on)
# the number of physicalcores equal to the half of the logical cores (pcore = lcores/2)
ht=`grep -o '^flags\b.*: .*\bht\b' /proc/cpuinfo | wc -l` # hyperthreading status
lcores=`grep -c ^proc /proc/cpuinfo` # number of logical cores
pcores=$(( $ht == 0 ? $lcores : $((lcores/2)) )) # number of physical cores
## 3. Burn your CPU
for i in $(seq $pcores)
do
t=$((TOUT + RANDOM%10))
echo "Run:$i timeout $t seconds"
timeout $t yes > /dev/null &
done
_EOF_
沒有留言:
張貼留言