需要对linux进行压测,网上找了一些脚本,会报错。因此将好用的脚本整理记录一下。
- cpu压测脚本
#! /bin/bash
# filename killcpu.sh
endless_loop()
{
echo -ne "i=0;
while true
do
i=i+100;
i=100
done" | /bin/bash &
}
if [ $# != 1 ] ; then
echo "USAGE: $0 <CPUs>"
exit 1;
fi
for i in `seq $1`
do
endless_loop
pid_array[$i]=$! ;
done
for i in "${pid_array[@]}"; do
echo 'kill ' $i ';';
done
- 内存压测脚本
#!/bin/bash
mkdir /tmp/memory
mount -t tmpfs -o size=300M tmpfs /tmp/memory
dd if=/dev/zero of=/tmp/memory/block
sleep 10s
rm /tmp/memory/block
umount /tmp/memory
rmdir /tmp/memory
网友评论