A Simple script to load & hammer the CPU using awk. The script does mathematical calculations and thus CPU load peaks up on higher values passwd to loadserver.sh . (Tested only on Linux)

The script loadserver.sh :

[root@foo313 ~]# cat loadserver.sh
#!/bin/sh

# unixfoo.blogspot.com

if [ $1 ]; then
        NUM_PROC=$1
else
        NUM_PROC=10
fi

for i in `seq 0 $((NUM_PROC-1))`; do
        awk ‘BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}’ &
done

echo “PIDS: `pidof awk`”

[root@foo313 ~]#

Before script execution :

[root@foo313 ~]# uptime
 09:22:18  up 14 days,  2:07,  3 users,  load average: 0.00, 0.02, 0.04
[root@foo313 ~]#

Script execution :

[root@foo313 ~]# ./loadserver.sh 10
PIDS: 11429 11428 11427 11426 11425 11424 11423 11422 11421 11420
[root@foo313 ~]# ps -ef | grep awk
root     11420     1 31 09:22 pts/1    00:00:01 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11421     1 45 09:22 pts/1    00:00:02 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11422     1 32 09:22 pts/1    00:00:01 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11423     1 29 09:22 pts/1    00:00:01 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11424     1 48 09:22 pts/1    00:00:02 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11425     1 45 09:22 pts/1    00:00:02 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11426     1 27 09:22 pts/1    00:00:01 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11427     1 46 09:22 pts/1    00:00:02 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11428     1 28 09:22 pts/1    00:00:01 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11429     1 34 09:22 pts/1    00:00:01 awk BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}
root     11450 11351  0 09:22 pts/1    00:00:00 grep awk

Check out the load :

[root@foo313 ~]# uptime
 09:22:44  up 14 days,  2:07,  3 users,  load average: 4.07, 0.93, 0.34
[root@foo313 ~]#

[root@foo313 ~]# mpstat 1
Linux 2.6.21 (foo313)        11/12/2008

09:24:56 AM  CPU   %user   %nice %system %iowait    %irq   %soft   %idle    intr/s
09:24:57 AM  all   99.00    0.00    0.75    0.00    0.00    0.25    0.00    678.79
09:24:58 AM  all   99.75    0.00    0.00    0.00    0.00    0.25    0.00    149.00
09:24:59 AM  all  100.00    0.00    0.00    0.00    0.00    0.00    0.00    113.00
09:25:00 AM  all   99.50    0.00    0.50    0.00    0.00    0.00    0.00    186.00

[root@foo313 ~]#

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
Read More

Netapp : Pocket Survival Guide

The url http://www.cs.fiu.edu/~tho01/psg/netapp.html has good information on netapp command set and its usage. A quick reference guide for…