How to kill your system

The image I use for “bash” articles contains a little bit of shell code that if used on the command line will hang your system, unrecoverably.

Explanation
A good place to start to understand the little piece of bash script in the image above is to RTFM (read the fine manual), in this case the Advanced Bash Scripting Guide plus actually do the examples provided in said guide and then WSFS (write some fine scripts) -without it you will never be good at it.

The code we are exmining:

$ :(){ :|:& };:

What does it do?

  1. The command is creating a bash function by the name ‘:’ , hence you see :().
  2. It places the body of the bash function called “:” within the curly braces { }.
  3. Inside the function definition (between the curly brackets) it calls itself, then pipes the output to itself.
    Now this is like a nuclear explosion 1 -> 2 -> 4 -> 8 -> 16 … I think you see where we are going with this – a very quick death.
    The & is putting this into the background, which enables this to execute in parallel.
  4. The “;” means “this is the end of the function definition”.
  5. The last “:” sets it all up, it actually calls the function “:” for the first time, this starts the sudden death of your workstation/server.

What this basically does, it calls the function the first time, then two processes are forked, then for each of the two processes two other processes are forked, then 8, then 16, then … you see where this is going?

The funny thing here that a fast computer is it’s own detriment – the faster the machine/architecture, the faster the death!

Let good coding be with you.

Leave a Comment

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

You must tick the checkbox for 'I am not a robot' before you can submit your comment!