Tuesday, April 28, 2015

produce 100% CPU Load in Linux

Today, I was going to boot my old Thinkpad T61 with a live USB drive to test my CPU fan noise and performance. I was also using "Psensor", a tiny GTK+ based application to monitor the temperature of my CPU cores and fan speed. I wanted to have a 100% load for this matter.
I first thought of writing a CPU hungry program like Factorial calculation as recursive functions in C and run it on my Ubuntu Linux. One of my friends at work suggested a nice hack!

if you just enter this in Terminal:

dd bs=1024 if=/dev/urandom of=/dev/null

and then check resources usage through "htop" utility. you will be amazed! one of my CPU cores is running on 100%!







/dev/urandom is kernel's random number generator and what we do is to copy 512 Bytes into /dev/null! as simple as that! so CPU is busy creating random numbers!

We can run it again to have both cores run on 100%!
To give CPU a relief, we can send SIGTERM by pressing Ctrl+C to terminate the task. here is a an output after running for 10 minutes on my system:

4723473+0 records in
4723472+0 records out
4836835328 bytes (4.8 GB) copied, 426.123 s, 11.4 MB/s

No comments: