linux模拟cpu占用100%脚本
vi killcpu.sh 脚本如下
#! /bin/sh
# filename killcpu.sh
if [ $# -ne 1 ] ; then
echo "USAGE: $0 <CPUs>|stop"
exit 1;
fi
stop()
{
while read LINE
do
kill -9 $LINE
echo "kill $LINE sucessfull"
done < pid.txt
cat /dev/null > pid.txt
}
start()
{
echo "u want to cpus is: "$1
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 'pid is: ' $i ';';
echo $i >> pid.txt
done
}
case $1 in
stop)
stop
;;
*)
start $1
;;
esac
运行方式:
chmod 777 killcpu.sh 修改文件权限777
./killcpu.sh 3 启动3个线程
top 查看cpu消耗文章来源:https://www.toymoban.com/news/detail-791384.html
停止:
killcpu.sh stop文章来源地址https://www.toymoban.com/news/detail-791384.html
到了这里,关于linux模拟cpu占用100%脚本的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!