【发布时间】:2018-03-18 18:04:17
【问题描述】:
Mac OSX 10.13.3。 系统泄漏实用程序在下一个代码中显示 4(两个 2048 和两个 16)泄漏:
#include <sys/wait.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
int st;
if (fork())
wait(&st);
else
while (1);
}
为什么?
【问题讨论】:
-
MacOSX libc 和 crt0 传闻泄漏。 IIRC,即使是 hello world 程序也在泄漏。不过还是自己试试吧(我用的不是MacOSX,而是Linux)
-
函数:
fork()有三种返回值 1) 0 表示现在在父进程中发布的代码无法处理错误 -
在子进程中,代码永远不会退出,所以父进程将永远等待。
标签: c macos unix memory-leaks fork