I am trying to understand under the hood how does fork
return the process id of the child since the child method has not returned, nor does it send by other mechanism its id to the parent. At the lowest level, I do not understand if lets say the child process is a long running loop:
//parent code
...some code...
Pid=fork([see below])
...some code...
//some file containing the executable code of the child process
void childProcessRunningMethod()
{
while(true);
}
Who is responsible for assigning the Pid
to the new process and when does that happen.How does whoever assigns the Pid
of the child work.
Does the child method gets overwritten into something like:
void childProcessRunningMethod(string parentPipeAddress)
{
var somePipe=new Pipe(parentPipeAddress);
somePipe.Open();
somePipe.Send([ Pid]); //somehow generates its own Pid
somePipe.Close();
while(true);
}