employer cover photo
employer logo
employer logo

Riverbed Technology

Is this your company?

Riverbed Technology interview question

what happens when you call fork() fork () fork()

Interview Answers

Anonymous

11 July 2012

A correction to Raj's formula is the following: Assuming M initial threads and N total forks, this will create a total of M * (2^N) threads. The fork() operation creates a copy of the process that called it. Step 1) That means that starting with 1 initial thread, you call the first fork() operation and you have two identical processes. [Total of 2 processes so far] Step 2) Those two identical processes then go on to call the 2nd fork(), which create identical processes of the two processes calling the operation. [Total of 4 processes so far] Step 3) Those four identical processes then go on to call the last remaining fork(), which create identical processes of the four processes calling the operation. [Total of 8 processes] I encourage anyone to correct any potential mistakes I might have made. The last thing I'd want is to wrongly inform someone going into an interview.

4

Anonymous

22 June 2011

@raj: Your formula doesn't quite work if there's only one thread running.

1

Anonymous

27 Jan 2010

8 processes(2^n) will be created

3

Anonymous

16 Sept 2010

Assuming M initial threads and N total forks, this will create a total of M * (M^N - 1) threads.