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

#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会将缓冲区里面的内容写回文件
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值