用法shell
./shell.sh 4 (4爲4內核)bash
查看cpu內核數量 > lscpuless
執行後會出現一堆kill命令,方便kill掉進程oop
- #!/bin/bash
- endless_loop()
- {
- echo -ne "i=0;
- while true
- do
- i=i+100;
- i=100done" | /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
shell消耗內存
之前有過[shell消耗cpu][1]的文章,再記錄一個shell消耗內存代碼。spa
- #!/bin/bash
- mkdir /tmp/memory
- mount -t tmpfs -o size=1024M tmpfs /tmp/memory
- dd if=/dev/zero of=/tmp/memory/block
- sleep 3600
- rm /tmp/memory/block
- umount /tmp/memory
- rmdir /tmp/memory
用tmpfs文件系統佔用內存一個小時進程