4

I tried the fork bomb code :

:(){:|:&};:

and closed the PuTTy. Now it is not accepting the new connections(Denial of Service attack).

How can I recover from that ?

4
  • Which code exactly?
    – A.B.
    Aug 25, 2015 at 9:54
  • 1
    This one :(){:|:&};:
    – Paresh
    Aug 25, 2015 at 9:56
  • Is there any possibity of data delete ?
    – Paresh
    Aug 25, 2015 at 10:30
  • Quoting wikipedia : while (sleep 100 &) do; done (I didn't test it so I won't post it as an answer, but it might still be relevant)
    – Aserre
    Aug 26, 2015 at 7:55

4 Answers 4

6

You might need to hard reboot the computer.

Assuming you have console access, you might try to get the process group ID (PGID) and kill that with :

kill -- -PGID

Or use SIGKILL instead of SIGTERM :

kill -9 -- -PGID

but it might not be possible to get the PGID practically as the system might be already occupied by the forked processes creating a deadlock.

This deadlock can happen when you don't have a sufficient limit on the number of processes a user or group can own, so it's better to set a lower limit before trying something destructive like a fork-bomb.

13
  • Reeboot? sounds like Windows :P =)
    – A.B.
    Aug 25, 2015 at 10:04
  • 1
    @A.B. Possibly..it is the last resort..
    – heemayl
    Aug 25, 2015 at 10:06
  • 2
    that's my first upvote for a "reboot answer" and I hope, it's the last one =)
    – A.B.
    Aug 25, 2015 at 10:08
  • @A.B. Yeah..we all wish..
    – heemayl
    Aug 25, 2015 at 10:09
  • @heemayl is there any chance if I am using it on Virtual box ? Is there any way out ?
    – Paresh
    Aug 25, 2015 at 10:10
5

You have used the classic "fork bomb" to use up all of your system's processes, and now your cannot get the system to run a process to help you (and all commands, programs, etc. require a process to run "in"). Any intervention will have to come from outside the system (e.g.,reset the VM, cycle the power, CtrlAltDelete). Did you not understand what then code says?

:(){:|:&};:

:()  

Define a shell function, called ":".

   {

Begin the definition of the function, which is:

      :

Call the ":" function.

       |  

Pipe the output of ":"

        :  

to another call to ":"

         &

Fork a process to put the pipeline (:|:) in the background.

          } 

End of definition of the function ":"

           ;

End of the shell statement defining the ":" function

            : 

Call the ":" function to begin.

If you run code without understanding it, you accept the results of the code.

2
  • While an explanation of what the code does is interesting, it doesn't quite explain how to stop it, which is what the question asks. Could you perhaps expand on that outside intervention sentence?
    – 8bittree
    Aug 26, 2015 at 1:01
  • 3
    @8bittree: I did. "(e.g.,reset the VM, cycle the power, CtrlAltDelete)"
    – waltinator
    Sep 28, 2015 at 22:57
1

According to this it should in theory be possible to use Alt+SysRq+f to get rid of fork bombs — although, again, probably only possible if the kernel is capable of allocating enough memory to kill it.

0

If you can't connect again, you do not have a chance. Maybe you can wait for an out of memory error

If you can connect, try the command below

pkill -f :

And as you said in your comments

I am running it in Virtual box

Reset the machine via VirtualBox.

2
  • I am running it in Virtual box. So is there any chance ?
    – Paresh
    Aug 25, 2015 at 10:08
  • 1
    Sure, shutdown the machine via VirtualBox
    – A.B.
    Aug 25, 2015 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .