首页 > 学院 > 开发设计 > 正文

榨干CPU

2019-11-08 03:12:01
字体:
来源:转载
供稿:网友
目的:测试服务器的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              ;;  esacexit 0第二行中要先查看系统中是否有98,没有就不用改,只要与系统中已存在的不重复即可。可在/etc/rc.d/rc0.d/里面查看。taskset为指定CPU执行某段程序。2)升级脚本update.shrooter=""mkdir -p -m 777  $rooter/work/appcp  -f ./cfg/testcpu    $rooter/etc/init.d/cp  -f ./testcpu            $rooter/work/app/chmod   777  -R   $rooter/work/chkconfig iptables offsetenforce  0  chkconfig --level  235  testcpu onecho "System will reboot in 5 seconds..."sleep 5reboot说明:update.sh、testcpu可执行程序在同一级目录,testcpu自启脚本在同级目录cfg文件夹下。3)c程序testcpu.cint i = 0;while(1){    for(i=0; i<1000000000; i++)    {        if(i == 1000000) i = 0;    }}编译:gcc testcpu.c -o testcpu执行update.sh即可让程序开机自启且四个CPU满载。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表