exit()函数与_exit()函数最大的区别就在于exit()函数在调用exit系统调用之前要检查文件的打开情况,把文件缓冲区中的内容写回文件.
即:
exit(): 会将缓存内容传给内核.
_exit(): 直接清空缓存,不会将缓存内容传给内核.
下面为分别测试exit()和_exit()
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
int main()
{
printf("hello\n");
printf("world");
_exit(0);
return 0;
}
执行该程序 输出为:hello
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
int main()
{
printf("hello\n");
printf("world");
exit(0);
return 0;
}
执行该程序 输出为:hello world