Linux Fork Bomb

:(){ :|: & };:Is a bash function, known as Fork Bomb, is a denial of service *** Linux system. If you executed this command curiously, then restart the system as soon as possible~!
Command analysis

    :()
{
    : | : &
};:

: Here is a function name, we define it and execute it later.
:|:&,: The output of the function is piped to another colon function as input and executed in the background.
{}; indicates that the content inside is a function body.
The last one: is a function execution after the definition is completed.

The principle analysis
first needs to explain: it is a shell built-in command, so the above code can only generate a fork bomb in bash, because in some other shells, built-in commands have higher priority than functions, so execute:, always Is to execute built-in commands. (: is an empty command, while true is equivalent to while:, often used as a placeholder)
Let's first look at the body of the function: |:&, when using a pipe, two processes start executing at the same time.
So when a: function is executed, two new processes are generated, and then one of the original processes exits, so that the recursion continues, resulting in an infinite recursion. According to this growth model, its growth trend is about 2n.

Guess you like

Origin blog.51cto.com/zhanx/2553865