使用死循环来消耗完若干个CPU
脚本内容
#! /bin/sh
# 参数个数不是1
if [ $# != 1 ] ; then
echo "USAGE: $0 [CPU count]"
exit 1
fi
cpu_count=$1
for ((i=1; i<=cpu_count; i++))
do
# 后台运行死循环
echo "
x=0
while true
do
x=x+1
done" | /bin/sh &
# 获取后台进程号
pids[$i]=$!;
done
for i in "${pids[@]}"
do
echo 'pid is '$i'';
done
现象
消耗1个CPU并输出后台运行的进程号
标签:count,消耗,echo,sh,USAGE,CPU From: https://www.cnblogs.com/WJQ2017/p/17205307.html