A simple program to freeze your computer

Harshal Parekh
Mar 16 · 2 min read

Ever wondered how does a piece of code look like that can lock up a traditional computer?

I have always had this curiosity and finally now I have explored and written enough to come up with a some really dangerous pieces of code that will do the job.

Fork Bomb: Very simple, yet effective. I came across the shell fork bomb years ago when I had to reboot the system. It looks like this:

Just a shell function that calls itself twice and never terminates.

This is how it look like in C. Well, this will get the job done, but nothing amazing about it.

How about allocating and leaking 1 KiB in an infinite loop? Let’s have a look at the code:

If you run this on a x64 machine, it is capable of locking up your RAM in just a few seconds. But this does not accomplish the job in all the environments, like if you run x86 on a x64 architecture, it can only lock up about 4GB of your RAM. Also, the processes that are already running, will continue running. Sometimes the mouse pointer will move around smoothly, but not respond to inputs.

How about generating huge pages and writing them to the memory?

This program will eventually finish. First, it will give itself the maximum priority. Then it starts generating huge memory pages with a random number generator so the OS allocates these pages.

Note: if you do not have the admin rights or sudo privileges, the priority setting code will fail.

I was able to kill the process, but the keyboard responded once in 5 seconds.

Write a comment if you have any more ideas!