Why this command crashes Linux [duplicate]

This is called a fork bomb.


The command defines a function named :, which, when called, spawns two copies of itself in the background and exits. Those two copies do the same, resulting in a huge amount of processes in just a second, continuing indefinitely.

Below is exactly the same function but with a more readable name:

foo() {
    foo | foo &
}

foo

It forks processes to background endlessly. After a while, there is too many processes, each taking small amount of system resources.


Technically speaking the system has not crashed. A system crash produces an exit with errors. It neither has hanged. This would imply that the system is doing something and has not returned. In the particular case it is working properly. It just takes too long to respond because a computer realization has finite resources. Hence infinite processes and finite resources result in infinite time to respond.