【发布时间】:2014-01-04 00:16:22
【问题描述】:
我正在尝试创建一个包含 2 个子进程的单父进程。当我运行我的代码时,我得到 3 个不同的子进程 ID。
int main ()
{
pid_t child_pid, child_pid1;
printf("the main program process ID is %d\n", (int) getpid());
child_pid = fork ();
if (child_pid != 0)
{
printf(" the parent process ID is %d\n", (int) getppid());
printf(" the child's process ID is %d\n", (int) child_pid);
}
child_pid1 = fork ();
if (child_pid1 != 0)
{
printf(" the child's process ID is %d\n", (int) child_pid1);
}
return 0;
}
【问题讨论】:
-
每个人都疯了!
-
你怎么知道你有 3 个孩子?
-
@MadPhysicist;因为父母很清楚:)
-
我会说我们应该在这个问题上坚持一个叉子,看看它是否完成! :)
标签: c fork parent-child