0

There are a couple of questions related to the fork bomb for bash :(){ :|: & };: , but when I checked the answers I still could not figure out what the exactly the part of the bomb is doing when the one function pipes into the next, basically this part: :|: .

I understand so far, that the pipe symbol connects two commands by connecting the stdandard output of the first to the standard input to the second, e.g. echo "Turkeys will dominate the world" | sed 's/s//'.

But I do not get it what the first function is pushing through its standard out, which gets pushed into the second one, after all there are no return values defined inside the function, so what is travelling through the human centipede if the man at the beginning has an empty stomach?

1 Answer 1

7

Short answer: nothing.

If a process takes in nothing on STDIN, you can still pipe to it. Simiarly, you can still pipe from a process that produces nothing on STDOUT. Effectively, you're simply piping a single EOF indicator in to the second process, that is simply ignored. The construction using the pipe is simply a variation on the theme of "every process starts two more". This fork bomb could also be (and sometimes is) also written as:

:(){ :&:; }; :

Where the first recursive call is backgrounded immediately, then the second call is made.

In general, yes, the pipe symbol (|) is used to do exactly what you mentioned - connect STDOUT of the first process to STDIN of the second process. That's also what it's doing here, even though the only thing that ever goes through that pipe is the single EOF indicator.

1
  • Another construction I have seen is :(){:&:&};:
    – DopeGhoti
    May 24, 2017 at 19:03

You must log in to answer this question.

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