Bifalgorithm post
This is one of the most dangerous pieces of code you can run on your computer. It's called a fork bomb. And if you run it, it will crash your machine. Definitely. So in this video, I'm definitely going to run this code, but first let's talk about how this works and why it's so dangerous. This code is a shell script and it's valid bash syntax. So you could just type it into your shell like I have here, or you can make a file that is executable and execute it. Either way, it works the same. Now to break this down, let's just talk about it really quick. It starts by declaring, function called colon. Now this is a bit of a trick. You see this function could be named anything, but in this script, we're calling the function colon because. It just looks cool. Next we have the body of the function and you can see it's denoted by the open and close squiggly braces next to the function definition. Now inside of the body of the function, we call this function recursively with colon, which as you can see is the name of the function itself. Then we pipe the output of the colon function to itself. And then we have an ampersand, which pushes the execution of the piped function call to the background. Now this is an important detail because background processes won't wait for the function to complete before running again. It will just run immediately and indefinitely. So what happens here is we fork a new process to run the function in the background indefinitely and this is what crashes your computer. Eventually you get too many processes taking up all the resources of your computer and eventually it just freezes and crashes. In fact, right here, I have a little bit of a diagram of exactly what happens. You see, we have the initial process, which spawns more processes, spawns more processes until eventually there's no more room left on your computer and no more memory and it crashes. And then we end the function declaration with a semi colon, which is typical in batch functions. And the last character, of course, calls this function colon. This starts off the whole entire thing that will definitely crash our computer by setting off the fork bomb. processes. So let's go ahead and run it and see what happens. I hit enter and then I open up Btop to just check on the resources. Oh, it looks like my screen's a little too small. I can make it a little bit bigger here. Okay. So now I see my resources and yep, it looks like every core of my machine is now taken up. My Ram is being used and a yeah, this doesn't look like it's doing too well here. Um, see if I can control C out of Btop and No, I can't. Oh boy, it's trying to fork processes and it can't because it looks like the fork bomb just took up everything in the computer. Uh, yeah, this computer is definitely messed up. Okay, I'm gonna restart my computer but subscribe for more Linux tips and tricks and hey, thanks nerds.
This is one of the most dangerous pieces of code you can run on your computer. It's called a fork bomb. And if you run it, it will crash your machine. Definite…
Ideas in this flowchart
- Fork Bomb Explanation
- Introduction
- Fork Bomb Code
- Code Execution
- Code Breakdown
- Function Declaration
- Recursive Call
- Background Execution
- System Crash
- Demonstration
- Resource Monitoring
- Outcome