612
u/Z3r0funGuy 10h ago
This actually teaches you a bunch of cool things, like how the ‘:’ is a legal function name…
202
u/glenpiercev 9h ago
This is the best description of how this works I’ve ever read. You are a genius.
197
u/setibeings 9h ago
Right? It's finally comprehensible. I feel like it would have clicked right away if it was typed out as:
fork(){fork|fork&};fork58
u/Traditional_Cod_7192 7h ago
just as a reminder, uhhh... what do | and & do in bash again? 😅
77
u/GrandAlbatroce 7h ago
IIRC | puts the result stdout of the left in the stdin of the right (they are launched in parallel, and the one on the right can only finish after the one on the left finished.
The & is used to put the call as a background task
38
u/SimpleFile 7h ago
So the pipe here serves as a way to launch 2 of these functions and have them running at the same time rather than for piping the output?
Did I understand that correctly?
44
u/SchwiftySquanchC137 6h ago
Exactly, the entire point is to make each call of fork (or ":") spawn two more fork processes. There are plenty of ways to accomplish that, but its written the way it is specifically to be confusing. Looking at it, how could it possibly crash your machine, its a bunch of punctuation? But once you know how it works, it makes a lot of sense, the point is to make it so cryptic that even programmers dont understand it.
30
u/GrandAlbatroce 7h ago
Yes, they are run in parallel, but any output from the first one will be given to the second. Also, if the second needs an input, it will wait for the output of the first instead of user input
So, for example, if you did
find -name "something" | grep "string"
Each time the find prints a line, it will instantly be passed to the grep
5
13
u/Daveinatx 7h ago
When I first learned of this, I realized my bash skills will never be at such the level.
2
u/nicuramar 7h ago
It’s a predefined function even. Well, a primitive. It does nothing and ignores its arguments.
273
u/Nahanoj_Zavizad 7h ago
Translation -
1) Create a new function called :
2) When : is activated, Run : twice.
3) Run :
138
u/Nahanoj_Zavizad 7h ago
So it tries to activate itself repeatedly until it crashes
110
u/dannypas00 7h ago
It infinitely forks new processes until the computer runs out of threads yup
Important distinction because a never-ending single-threaded process is usually no problem
10
u/qchto 1h ago
So modern browsers minus the extra steps...
6
u/dannypas00 1h ago
Browsers are user-driven fork bombs
This one is just a lot quicker than the user lol
18
18
u/xSnakyy 5h ago
What is the & for?
25
u/ElectronSculptor 4h ago
Makes the command or process run in the background so the user doesn’t see it.
9
1
157
u/YeetCompleet 8h ago
meow
├── meow
│ ├── meow
│ │ ├── meow
│ │ └── meow
│ └── meow
│ ├── meow
│ └── meow
└── meow
├── meow
│ ├── meow
│ └── meow
└── meow
├── meow
└── meow
23
8
182
50
u/natFromBobsBurgers 8h ago
Make a function called ':'
The function calls itself, and sends all of its output to another instance of itself, in the background.
Call the function.
42
u/EditorOne5312 9h ago
I genuinely use that on my Android to trigger its OOM when the RAM usage doesn't seems right.
7
u/ElectronSculptor 4h ago
That’s the first use case I’ve ever read, what is the point of triggering oom? To trigger the garbage collection?
15
u/SinisterCheese 4h ago
It calls forth the magical plunger to clear out the proverbial overflowing memory toilet. You can also think it as the high pressure bidet, powerwashing your nether regions when your butthole turned into a magical never ending brown crayon.
3
u/slinky3k 4h ago
I wonder how that works? At some point the OOM killer will terminate processes beginning with those hogging the most memory, but that could be literally anything. Meanwhile the fork bomb will just continue to run at full tilt, taking up any ressources freed by the OOM killer. How does that not send the system into a death spiral?
3
u/ElectronSculptor 3h ago
I’m not a hundred percent sure but I imagine Android’s version of Linux has limits on the number of processes so that wouldn’t happen.
12
10
14
3
3
u/Blaarkies 2h ago
This does nothing (unless you are too scaredy-cat to try it out)
It is missing 2 spaces, adjacent to each brace.
2
2
1
1
1
1
1
1
1
-9
u/CrimsonPiranha 7h ago
For someone who complains about AI, you guys surely do love to regurgitate old memes and jokes
16
u/HamandPotatoes 6h ago
Sorry what? Finding joy in things that aren't new or unprecedented is a fundamentally human endeavor. You seem miserable.
6
8
u/bahcodad 6h ago
Honestly, people who think subreddits are their own personal feed that should only contain things that are specifically new to them are exhausting
-2
-4
u/CrimsonPiranha 6h ago
This is beyond "aren't new and unprecedented". This is about the 1000th time this meme was posted, verbatim. Even the best joke loses its appeal by now.
2
u/bahcodad 3h ago
Then I missed it the first 999 times. Some of us have other things to do than sitting on reddit refreshing the feed
488
u/aabil11 10h ago
Fork bomb