【发布时间】:2021-02-07 03:40:23
【问题描述】:
我试图了解 fork 如何返回子进程 ID,因为子方法没有返回,也没有通过其他机制将其 id 发送给父进程。在最低级别,我不明白是否可以说子进程是一个长时间运行的循环:
//parent code
...some code...
Pid=fork([see below])
...some code...
//some file containing the executable code of the child process
void childProcessRunningMethod()
{
while(true);
}
谁负责将Pid分配给新进程,什么时候发生。分配Pid子进程的人是如何工作的。
子方法是否被覆盖为:
void childProcessRunningMethod(string parentPipeAddress)
{
var somePipe=new Pipe(parentPipeAddress);
somePipe.Open();
somePipe.Send([ Pid]); //somehow generates its own Pid
somePipe.Close();
while(true);
}
【问题讨论】:
标签: operating-system fork pid systems-programming