【发布时间】:2011-10-07 22:40:29
【问题描述】:
假设函数 func 有 bug 导致内存泄漏。
pid_t childPid;
int status;
childPid = fork();
if (childPid == -1)
errExit("fork");
if (childPid == 0) /* Child calls func() and */
exit(func(arg)); /* uses return value as exit status */
/* Parent waits for child to terminate. It can determine the
result of func() by inspecting 'status'. */
if (wait(&status) == -1)
errExit("wait");
问题 1> 如果一个程序发生了内存泄露,那么程序最终退出后,是否还会泄露内存,还是系统会收集该程序分配的所有内存,再没有泄露的内存?
问题 2> 父进程调用wait后,子进程的func导致的内存泄露是怎么回事?
【问题讨论】:
标签: c linux ubuntu-10.04