Nate Houk
Nate Houk

Reputation: 365

What does the pipe | do in this bash script?

I am trying to understand this so called "Fork Bomb" written in bash. (for more information see https://en.wikipedia.org/wiki/Fork_bomb)

My understanding is that the Ampersand caused the function Bomb to be forked and to run in the background. Is that correct?

Presuming so... my question then is, what does the Pipe | do?

Is the pipe in this case an OR condition, or is it the same as "piping" a command from one to the other as done on the command line? Why do I want to pipe the second Bomb function call back to the first Bomb function call?

Can someone please explain why the pipe is necessary?

bomb(){
  bomb | bomb & 
}
bomb

Upvotes: 0

Views: 95

Answers (1)

Wiimm
Wiimm

Reputation: 3492

Each call of function bomb starts 2 new instances of bommb in the background. Because of the pipe sign, the output (is empty here) of the first bomb is redirected to the second one.

Because of background execution, each new bomb creates 2 new bombs. That is done endless, so that at any time the number of available processes is reached. Dependent of available resources and rights, the system goes very slow for a time or crashes.

Upvotes: 2

Related Questions