linux cpu吃资源脚本,消耗CPU资源的shell脚本

#! /bin/sh

# filename killcpu.sh

if [ $# != 1 ] ; then

echo "usage: $0 "

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 进程:

[root@test02 ~]# ./killcpu.sh 3

kill  30104 ;

kill  30106 ;

kill  30108 ;

[root@test02 ~]# top

top - 15:27:31 up 264 days, 23:39,  4 users,  load average: 0.86, 0.25, 0.19

tasks: 185 total,   5 running, 180 sleeping,   0 stopped,   0 zombie

cpu0  : 100.0% us,  0.0% sy,  0.0% ni,  0.0% id,  0.0% wa,  0.0% hi,  0.0% si

cpu1  :  0.0% us,  0.0% sy,  0.0% ni, 100.0% id,  0.0% wa,  0.0% hi,  0.0% si

cpu2  : 100.0% us,  0.0% sy,  0.0% ni,  0.0% id,  0.0% wa,  0.0% hi,  0.0% si

cpu3  : 100.0% us,  0.0% sy,  0.0% ni,  0.0% id,  0.0% wa,  0.0% hi,  0.0% si

mem:   8165004k total,  8095880k used,    69124k free,    53672k buffers

swap:  2031608k total,   103548k used,  1928060k free,  6801364k cached

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值