Understanding Fork Bombs in 5 Minutes or Less

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ธ.ค. 2024

ความคิดเห็น • 134

  • @EngineerMan
    @EngineerMan  ปีที่แล้ว +456

    Warning: Don't run this on your own system. If you want to test it, create a VM like I did.

    • @VRixxo123
      @VRixxo123 ปีที่แล้ว +24

      Why not. Does it not go away ?

    • @acu01136
      @acu01136 ปีที่แล้ว +18

      Surely hard rebooting the system stops the issue though? With all the normal problems with hard reboots ofcourse.

    • @benargee
      @benargee ปีที่แล้ว +25

      He probably means that it's the easiest environment to test in and as a general disclaimer to not mess up a system critical machine. At the end of the day you can do whatever you want with your own hardware, just that he's not endorsing it.

    • @daidaloscz
      @daidaloscz ปีที่แล้ว +58

      Nobody can stop me from running this on our production cluster.
      (I have sudo)

    • @iuhere
      @iuhere ปีที่แล้ว +8

      Someone (YKIYK) said -
      Why are the warnings at the end of the book 😉

  • @demipy
    @demipy ปีที่แล้ว +240

    I know this classic for over a decade now, but this was such a great video explaining it in detail! Thats the content i love this channel for. No BS straight to the point. ❤

  • @lillii9119
    @lillii9119 ปีที่แล้ว +175

    Short version: it creates a function called : that calls itself infinitely
    Also it calls 2 functions for each function which run at the same time so each step the number of functions is doubled

    • @glukogen5674
      @glukogen5674 ปีที่แล้ว +10

      *Force Multiplication*

  • @flipperiflop
    @flipperiflop ปีที่แล้ว +78

    Great explanation! The expanded version really made it go from black magic to "oh it's that simple"

  • @tc2241
    @tc2241 ปีที่แล้ว +52

    I love videos like these. Straight to the point, clearly explained with concise examples and demonstrations

  • @paulm3702
    @paulm3702 ปีที่แล้ว +17

    Wow that's interesting! Love the breakdown of how that code actually worked

  • @alicefraser5799
    @alicefraser5799 ปีที่แล้ว +8

    That's why I love your content EM. Learning so much from you. Keep them coming :)

  • @revx144
    @revx144 10 หลายเดือนก่อน +2

    I actually did this in my phone, good thing I did some buttons and it restarted. I was so scared but I was relieved when it restarted successfully.

  • @YammoYammamoto
    @YammoYammamoto 11 หลายเดือนก่อน +1

    The colon being a valid function name was what blew my mind. :D

  • @rogo7330
    @rogo7330 ปีที่แล้ว +27

    Pipe is not the real issue here that causes program to explode. When you running a function, shell executes whatever command you gave it (and forks itself to execute external programs), but ampersand makes shell not to wait for a job to complete and then return but instead put that job in a background and let user to cleanup it with a wait command manualy.
    What is a job? Job is basically a group of processes with the same Process group ID (read manpage 7 credentials to learn more). Shell, when you launch several command with a pipe between them, first calls fork, then in a child assigns the same PGID as it's PID to itself, then it calls more forks which will inherit the same PGID (despite having new PIDs) with their stdins and stdouts connected one to another, and then each of that child executes whatever command you gave it to execute.
    Why PGID needed? To call kill command on the whole group of processes with the same PGID instead of calling kill to each one of them, or even lose control when initial child died and replaced itself with a new process with new PID. Since PGID is inherited by the child, and if child does not changes it explicitly by calling setpgid, you can just `kill -- -${child_pid}` (notice the minus before the process id and double-minus to make kill take that negative pid not as another option but as a pid value). This is how shell kills the whole pipe sequence at once.
    And yes, if child changes its PGID, its becoming immune to group kill (the game was rigged from the start), which does makes sence, but its hard to work around this if you really want to end all child and grandchildren processes, if at all possible. Try to write cron yourself, you will spend on it at least a hour or two of experimenting with what works and what not if you start from scratch knowing nothing about jobs, PGID, SID, what kill and wait calls allow you to do and what permissions you have to play with for changing processes credentials.

  • @comosaycomosah
    @comosaycomosah ปีที่แล้ว

    dude idk how i havent came across your content yet but i dig it.

  • @warchild3948
    @warchild3948 ปีที่แล้ว +1

    " this is the initial call to fork me"
    How did you say that with a straight face.. Cuz I am rolling 😂 😂

  • @alexanderaphonin7850
    @alexanderaphonin7850 ปีที่แล้ว +2

    Great video, great explanation! Thank you for putting in the effort each time!

    • @EngineerMan
      @EngineerMan  ปีที่แล้ว

      Thanks for the kind words.

  • @nnutipa
    @nnutipa ปีที่แล้ว +13

    Thanks. But the most interesting part with pipe and fork itself were not covered:( You said pipe is what actually creates a fork bomb, but why?

    • @patocarrasco6266
      @patocarrasco6266 ปีที่แล้ว +8

      yeah, I also missed that. In my head, the second argument is waiting for the given input by the first one, so it should remain inactive. The only thing that I know is that the prior is wrong xD

    • @prontomatias3081
      @prontomatias3081 ปีที่แล้ว

      look at @rogo7330 comments

    • @DerMigi
      @DerMigi ปีที่แล้ว

      @@patocarrasco6266this is the exact same question I have. Does anyone have an answer?

    • @Turalcar
      @Turalcar 11 หลายเดือนก่อน +2

      Piped processes are launched by bash in parallel

  • @ABaumstumpf
    @ABaumstumpf ปีที่แล้ว +3

    You can do the same on Windows, but normally the system does not outright crash and you can recover from that (with taskmanager).

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz ปีที่แล้ว +10

    Cant you do the same thing without the pipe? It feels like
    f(){f&}; f should do the same job. If you want to increase the forks exponentially, just have each function run two other ones like so:
    f(){f&; f&}; f

    • @ktheveg
      @ktheveg ปีที่แล้ว +1

      Might be written with a pipe to make things neater or smaller

    • @prontomatias3081
      @prontomatias3081 ปีที่แล้ว

      look at @rogo7330 comments

  • @yousefm.b4260
    @yousefm.b4260 ปีที่แล้ว +1

    Wow!! this guy actually explained it very well.. I like it

  • @matejhurta5626
    @matejhurta5626 ปีที่แล้ว +3

    I kinda accidentally let it loose on the uni network and it crashed the network for a few days and I got failed :(

  • @binbashbuddy
    @binbashbuddy ปีที่แล้ว

    I've seen it a number of times recently. Used to be kind of common, then it seemed to get old and I didn't see it so much, now it seems to be common again.

  • @okunamayanad
    @okunamayanad ปีที่แล้ว

    i understood the fork bomb at 1:00 great title

  • @lancemarchetti8673
    @lancemarchetti8673 11 หลายเดือนก่อน +3

    Cool! I've created a jpeg bomb of 530 bytes that renders 4 billion pixels to the screen when opened. It freezes my laptop.. lol.
    I achieved this neat trick in Notepad ++ by accident when editing the Hex values in the dimensions sector of the code....

  • @n8style
    @n8style ปีที่แล้ว +1

    Fantastic explanation, quality video

  • @h3dzer
    @h3dzer ปีที่แล้ว

    I love this new series

  • @loverboykimi
    @loverboykimi ปีที่แล้ว +1

    Great education. Appreciated.

  • @saptamdutta
    @saptamdutta 7 หลายเดือนก่อน

    hey guys i want to know what other pranks have u done like this?

  • @ameen4912
    @ameen4912 16 วันที่ผ่านมา

    what to do if you get this error
    bash: syntax error near unexpected token `{:'
    or
    Unsupported command: :(){

  • @chawrx3
    @chawrx3 ปีที่แล้ว

    keep it up brother, have a nice day everyone

  • @Apersonl0l
    @Apersonl0l ปีที่แล้ว +2

    so it's basically how all my recursion functions go? :))))

  • @willmckeand
    @willmckeand ปีที่แล้ว +1

    Pipe bomb would've been a great name for this

  • @Baltr
    @Baltr ปีที่แล้ว +1

    are you able to pipe it multiple times inside the same command to make it crash the system faster?

    • @alexholker1309
      @alexholker1309 ปีที่แล้ว

      I don't think it would make a meaningful difference. You'd crash the system in fewer generations, but it would take longer to resolve each instance of the process.

  • @cepi24
    @cepi24 ปีที่แล้ว

    How did you replace semicolons with text?

  • @macethorns1168
    @macethorns1168 ปีที่แล้ว +4

    The only reason I was confused when I first saw this was that I didn't know you could use a colon as a function name. It makes much more sense as f(){f|f&};f
    It seems many modern 'nux systems default to limiting the number of forks a process can start now.

  • @aepokkvulpex
    @aepokkvulpex 14 วันที่ผ่านมา

    What does the semicolon mean?

  • @BradenJohnYoung
    @BradenJohnYoung ปีที่แล้ว

    Great explanation

  • @prinnydadnope5768
    @prinnydadnope5768 ปีที่แล้ว

    Very clear, thank you again

  • @victorsubbiah6077
    @victorsubbiah6077 11 หลายเดือนก่อน

    shouldn't proliferating dummy processes just hang the system forever?
    why would it crash the system anyway?

  • @penguinpatroller
    @penguinpatroller ปีที่แล้ว

    great video. concise and informative

  • @bashisobsolete.pythonismyn6321
    @bashisobsolete.pythonismyn6321 ปีที่แล้ว

    when you use fish shell for several good reasons and the "expert professionals" roll their eyes at you.

  • @iskuben88
    @iskuben88 ปีที่แล้ว

    great video! Brings back memories of crashing uni sun-ray clients ;)

  • @SomeGuyInSandy
    @SomeGuyInSandy ปีที่แล้ว

    You have to love it!

  • @sam_ldm
    @sam_ldm ปีที่แล้ว

    what if i write this in my bashrc ?

  • @Evercreeper
    @Evercreeper ปีที่แล้ว

    Excellent video

  • @Drogobo
    @Drogobo ปีที่แล้ว

    what do you mean by "friends on linux"?

  • @headlights-go-up
    @headlights-go-up ปีที่แล้ว

    great explanation!

  • @siri-v18.x-intelligence-beta
    @siri-v18.x-intelligence-beta 7 หลายเดือนก่อน

    do you need the &?

  • @davidserrano2091
    @davidserrano2091 ปีที่แล้ว +1

    Time to run it on my system

  • @connorallen162
    @connorallen162 ปีที่แล้ว +1

    Oh THAT's why you don't want everything to be run by the root user

  • @richarduton
    @richarduton ปีที่แล้ว +1

    This isn't a fork bomb it's a picture of a cat.

  • @RlainTheFirst
    @RlainTheFirst ปีที่แล้ว

    What about :(){:&;:&);:
    Also exponential or linear?

    • @patfre
      @patfre ปีที่แล้ว

      It will do the same as at 4:25

  • @hkkis7836
    @hkkis7836 ปีที่แล้ว

    Could you please show your hotkeys for the editor?

  • @L-Coder
    @L-Coder ปีที่แล้ว

    type the command 'gnome-terminal' (or any other command that opens a bash shell) in the end of the .bashrc file and save it and then see the magic when you open a terminal.😂 You might to do it in the .zshrc file depending on the type of shell you are using (bash or zsh = Bourne Again Shell or Z shell).

  • @takuya.yagami.
    @takuya.yagami. ปีที่แล้ว

    Great video

  • @docker31c
    @docker31c ปีที่แล้ว +1

    So i got trolled in a stackoverflow question...

  • @SoreBrain
    @SoreBrain ปีที่แล้ว +1

    It's tempting

  • @devviz
    @devviz ปีที่แล้ว

    if you set the video playing speed fast enough you can almost hear "fork me" to another very similar term

  • @theoreticalaxolotl2804
    @theoreticalaxolotl2804 6 หลายเดือนก่อน

    My roommate will love this prank

  • @iangraham6730
    @iangraham6730 ปีที่แล้ว

    Noice 👌 Thanks for sharing 👍

  • @philipzhu5194
    @philipzhu5194 ปีที่แล้ว

    What happens if instead of piping, you start 2 background processes each time? like :(){:&:&};:

  • @m3sm4r2010
    @m3sm4r2010 ปีที่แล้ว +1

    fyi: i have tested this code on my android phone and it works 😂

  • @ai-spacedestructor
    @ai-spacedestructor ปีที่แล้ว

    the VM setup is questional, you said you had to restart your system and the VM. sounds like you gave it too much pc resources or using some vm i never heard about before which doesnt asign a limited number of resources in order to run it.

    • @EngineerMan
      @EngineerMan  ปีที่แล้ว

      I only had to restart the VM, not my whole system.

    • @ai-spacedestructor
      @ai-spacedestructor ปีที่แล้ว

      @@EngineerMan you did say in the video something about your vm and the whole system after it crashed. might have misunderstood but to me it did sound like you said you had to restart the whole system.

  • @mrdzha9519
    @mrdzha9519 11 หลายเดือนก่อน

    thanks, it was interesting!

  • @mynameismynameis666
    @mynameismynameis666 ปีที่แล้ว

    forbidden emojis are teh most powahful

  • @rebel478
    @rebel478 ปีที่แล้ว

    Oh no I'm wrong, your right eyebrow is still always higher than the other one

  • @EnglishRain
    @EnglishRain ปีที่แล้ว

    Nice didn't know you could limit number of processes for a user

  • @GeorgeAlexanderTrebek
    @GeorgeAlexanderTrebek ปีที่แล้ว

    Spoon Nuke next plz

  • @repairstudio4940
    @repairstudio4940 ปีที่แล้ว

    Awesomeness 🎉

  • @adrianbool4568
    @adrianbool4568 ปีที่แล้ว

    Fork me, that was a good video! ;-)

  • @joey3070
    @joey3070 11 หลายเดือนก่อน

    Delightful

  • @garrysingh4484
    @garrysingh4484 ปีที่แล้ว

    Awesome 👍

  • @KangJangkrik
    @KangJangkrik ปีที่แล้ว +1

    Ran this on production server for fun, bos didn't seem really enjoy it

  • @mikerope5785
    @mikerope5785 ปีที่แล้ว

    i was sad when browsers started detecting and halting infinite javascript recursions

  • @The_Pariah
    @The_Pariah ปีที่แล้ว

    So you watched Dave's Garage and made your own fork bomb video. K.

  • @shahfaisal3923
    @shahfaisal3923 ปีที่แล้ว

    you won a subscriber

  • @Angelinajolieshorts
    @Angelinajolieshorts 10 หลายเดือนก่อน

    Can you please tecah us these skills. Please 🙏🙏🙏

  • @Cassandra_Johnson
    @Cassandra_Johnson ปีที่แล้ว

    ah yes, for(;;){fork();} good times...

  • @cni_povkit
    @cni_povkit ปีที่แล้ว +5

    "Fork me". That's what she said.

  • @tobiashelbing1233
    @tobiashelbing1233 ปีที่แล้ว

    Great!

  • @iuhere
    @iuhere ปีที่แล้ว

    stress testing without a stop 🛑 button 😅

  • @chromosome24
    @chromosome24 11 หลายเดือนก่อน +1

    I prefer the spoon bomb

  • @HiddenTreasure-xj7yt
    @HiddenTreasure-xj7yt ปีที่แล้ว

    I made a batch bomb in the 90s.

  • @danielbaker1248
    @danielbaker1248 9 หลายเดือนก่อน

    Fork me, this is interesting!(:

  • @cmoor8616
    @cmoor8616 ปีที่แล้ว

    Reminds me of the prankster batch files for cmd.exe I used to make during my windows years. The simplest I managed to create (DO NOT RUN THIS)
    %0 >> %0
    %0
    With an empty line after,

  • @K_Forss
    @K_Forss ปีที่แล้ว

    I remember my first attempt at a fork bomb, it was perhaps 15 years ago in high school and I wrote it in C, it didn't really work too well, I probably had some more advanced scheduler than I thought and while it slowed down my computer I was able to still kill the process. But I added a small malloc (about 4k if I remember correctly) in the loop ant it totally freezed my computer in seconds. Fun times
    Edit: If I had known more when I was young I'd probably done a mix of forking and daemonizing to try to hit it harder

  • @clockblower6414
    @clockblower6414 ปีที่แล้ว +1

    You can fix a lot of problems in Linux by running sudo dd if=/dev/null of=/dev/sda

  • @googleuser4720
    @googleuser4720 ปีที่แล้ว

    Is your name a Daniel?

  • @florianmattausch8563
    @florianmattausch8563 ปีที่แล้ว

    It is Not exponential. it is just times 2.

    • @patfre
      @patfre ปีที่แล้ว +5

      Exponential is repeated multiplication. So it is exponential because it is multiplying by 2 over and over

  • @kiyasuihito
    @kiyasuihito ปีที่แล้ว

    Hilarious 🎉

  • @pratikdhage
    @pratikdhage 2 วันที่ผ่านมา

    This meme ❤️😁😁

  • @Alex-eq1cs
    @Alex-eq1cs 8 หลายเดือนก่อน

    Systemd solution this.... Límite del 30% de procesos máximos del sistema.

  • @rebel478
    @rebel478 ปีที่แล้ว

    How is your eyebrow straight again

  • @enty-3035
    @enty-3035 9 หลายเดือนก่อน

    %0|%0 is the windows version it is fun

  • @colonthree
    @colonthree ปีที่แล้ว

    Cat :3

  • @cruz1ale
    @cruz1ale ปีที่แล้ว

    fork bombs are for dorks

  • @Pcoxproductions
    @Pcoxproductions 4 หลายเดือนก่อน

    There are no shortcuts

  • @MrGeekGamer
    @MrGeekGamer ปีที่แล้ว

    "There is ways"
    There are.

  • @mikebresnahan8682
    @mikebresnahan8682 ปีที่แล้ว

    Being an old fart, I have to point out that the fork bomb existed prior to linux, albeit with the same shell syntax you describe. en.wikipedia.org/wiki/Fork_bomb

  • @darienverdugo290
    @darienverdugo290 ปีที่แล้ว

    What if i run it on an instance 🥸

  • @DUMBDUDEGAMER
    @DUMBDUDEGAMER ปีที่แล้ว

    I wonder how this does on WSL

  • @jackflowt
    @jackflowt ปีที่แล้ว

    Great explanation!