Linuxfork bomb analysis-LinuxForkBomb
Linux Fork Bomb
:() {:| :&};:Is a bash function, known as Fork Bomb, and is a Linux system that is vulnerable to DoS attacks. If you are curious to execute this command, restart the system ~!
Command Parsing
:(){ : | : &};:
:Here is a function name. We define it and execute it later.: | :&,: The function output is transmitted to another colon function as the input through a pipeline and executed in the background.{};It indicates that the content is a function subject.Last one:Is the execution of the evaluate function after the definition is complete.
Principle Analysis
The first thing to note is::Is a shell built-in command, so the above Code can only generate a fork bomb in bash, because in some other shells, the built-in command has a higher priority than the function, so execute:Always execute built-in commands. (:Is an empty command, while true is equivalent to while:(Commonly used as placeholders) First, let's take a look at the main body of the function.: | :&When using pipelines, two processes start to execute at the same time. Therefore, when you execute:When a function is used, two new processes are generated, and then an original process exits, so that the recursion continues continuously and an infinite recursion is generated. According to this growth model, the growth trend is about 2n .
Summary
There are many such traps in Linux, which is exactly why I like Linux and is full of exploration.