exit函数和_exit函数之间的区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/linxizi0622/article/details/73558043
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>




int main()
{


     pid_t result;
     result = fork();
     if(result<0)
     perror("fork");
     if(result == 0)
     {
             printf("This is _exit test\n");
             printf("This is the content in the buffer000");
_exit(0); 


     }
     else
     {
             printf("This is exit test\n");
             printf("This is the content in the buffer");
            exit(0);            
     }
     return 0;
}
这是别人的实例代码,我借用一下哈
这里说明一下,printf是标准io函数,当遇到\n换行符的时候,才会将缓冲区里面的内容进行输出
运行结果是
This is exit test
This is the content in the buffer
This is _exit test
首先输出的是父进程里面的内容,首先将
This is exit test放进缓冲区,然后遇到换行符,输出This is exit test
然后将This is the content in the buffer放进缓冲区,
然后exit(0)由于,exit函数会冲洗缓冲区,那么
This is the content in the buffer也会被输出
接下来就是子进程了,首先
This is _exit test放进缓冲区
然后遇到换行符,输出内容
接下来把
This is the content in the buffer000放进缓冲区,由于没有换行符
并且_exit(0函数不会冲洗缓冲区,所以This is the content in the buffer000
这条语句不会输出
那么exit函数和_exit函数之间的区别就是exit会将缓冲区里面的内容写回文件

猜你喜欢

转载自blog.csdn.net/linxizi0622/article/details/73558043
今日推荐