Hey. I need to learn about forks and execs for school. I spent whole day on it and still does not understand it fully.
Here is exercise from the test.
Could someone write step by step what is program doing?
I need process tree for it.
IMHO, you should explain what you are confused with... The concept of fork and exec is really straightforward, and it is just two function calls -- there really isn't much to explain. Perhaps if you explain what you are confuse with, we can target that.
As it is silly, and no real application will do this... okay, the program hits the fork() in the condition, and becomes two processes.
The child process with get a zero result and goes to the next line. The parent process get the PID of the child, which of course, is not zero, and ... execute the second fork(). This means that the parent process becomes two process again. Both of these two processes will go to the next line.
At this point, you have three processes, which will executes the next line... the rest you should be able to figure out yourself....
must Janik wrote:Yea. Okey got it. What about this process tree?
It should be easy to go from the description to a diagram that puts the description in graph form. Did you work out the rest? If not, tell us what you did so far. If so, show us what you draw out so far. And of course why.