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 ?

heemayl
  • 93,925
Paresh
  • 43

4 Answers4

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.

Fabby
  • 35,017
heemayl
  • 93,925
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.

waltinator
  • 37,856
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.

Fabby
  • 35,017
A.B.
  • 92,125