Let's say we have this code:
main
some code...
fork()
fork()
some code
The question is: How many threads are running?
Thank you !
Thanks to the help of Jeremy I figured out the answer and want to share it with you.
In general if we have a fork() a child is created. Unless we have a different code for the child the child runs the code of the parent (aka the code under fork() ). So in this example the 1st fork will create a new process as it will run the second fork.
So we have 1 thread for the parent. 1 second thread for the child1 from fork1. 1 third thread from the child1 due to fork2. And finally a thread from the child2. So in total there are 4 threads.