使用死循環消耗CPU資源,若是服務器是有多顆CPU,能夠選擇消耗多少顆CPU的資源:shell
#! /bin/sh
# filename killcpu.sh
if
[ $
# != 1 ] ; then
echo
"USAGE: $0 <CPUs>"
exit
1;
fi
for
i
in
`
seq
$1`
do
echo
-
ne
"
i=0;
while
true
do
i=i+1;
done
" |
/bin/sh
&
pid_array[$i]=$! ;
done
for
i
in
"${pid_array[@]}"
;
do
echo
'kill '
$i
';'
;
done
使用方法很簡單,參數3表示消耗3顆CPU的資源,運行後,會有一堆 kill 命令,方便 kill 進程:
服務器