消耗CPU资源的shell脚本
2016-08-02 12:27
323 查看
#! /bin/sh
# filename killcpu.sh
if [ $# != 1 ] ; then
echo "USAGE: $0 <CPUs>"
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
# filename killcpu.sh
if [ $# != 1 ] ; then
echo "USAGE: $0 <CPUs>"
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
相关文章推荐
- 消耗CPU资源的shell脚本
- 消耗CPU资源的shell脚本
- [原]消耗CPU资源的shell脚本
- linux消耗CPU的shell脚本
- 编写shell脚本查看linux当前各用户的cpu和memory消耗比例
- shell脚本消耗机器的CPU实例
- CPU资源的shell脚本
- shell脚本02--记录系统资源消耗
- 占用CPU资源的shell脚本
- shell脚本消耗机器资源
- shell模拟程序消耗CPU资源
- 自动杀掉占用较多CPU资源的Shell脚本
- 自动杀掉占用较多CPU资源的Shell脚本
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- cpu负载监控shell脚本
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- shell脚本监控系统负载、CPU和内存使用情况
- 统计 cpu 内存 使用率的shell脚本代码
- 利用shell脚本来监控linux系统的负载与CPU和内存使用情况