榨干CPU

目的:测试服务器的CPU性能,让四个CPU满载。
1)自启动脚本testcpu:
#!/bin/bash  
# chkconfig: 2345 98 5  
# description: script to start/stop testcpu 
case $1 in  
    start)  
            cd /work/app  
            taskset -c 0 ./testcpu & 
            taskset -c 1 ./testcpu &
            taskset -c 2 ./testcpu &
            taskset -c 3 ./testcpu &
            ;;  
    stop)  
            pkill testcpu
            ;;  
      *)  
            echo "Usage: $0 (start|stop)"  
            exit 1  
            ;;  
esac

exit 0

第二行中要先查看系统中是否有98,没有就不用改,只要与系统中已存在的不重复即可。可在/etc/rc.d/rc0.d/里面查看。
taskset为指定CPU执行某段程序。

2)升级脚本update.sh
rooter=""

mkdir -p -m 777  $rooter/work/app

cp  -f ./cfg/testcpu    $rooter/etc/init.d/

cp  -f ./testcpu            $rooter/work/app/

chmod   777  -R   $rooter/work/

chkconfig iptables off
setenforce  0  
chkconfig --level  235  testcpu on
echo "System will reboot in 5 seconds..."
sleep 5
reboot

说明:update.sh、testcpu可执行程序在同一级目录,testcpu自启脚本在同级目录cfg文件夹下。
3)c程序testcpu.c
int i = 0;
while(1)
{
    for(i=0; i<1000000000; i++)
    {
        if(i == 1000000) i = 0;
    }
}

编译:gcc testcpu.c -o testcpu
执行update.sh即可让程序开机自启且四个CPU满载。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值