exit函数和_exit函数之间的区别
2017-06-22 08:54
169 查看
#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会将缓冲区里面的内容写回文件
#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会将缓冲区里面的内容写回文件
相关文章推荐
- exit() 与 _exit() 函数调用之间的区别
- exit函数和return返回之间的区别
- QT中关闭应用程序和窗口的函数(quit(),exit()以及close()的区别)
- 【PHP】别名函数之die()与exit()的真正区别
- exit()函数与_exit()函数及return关键字的区别: exit()和_exit()函数都可以用于结束进程,不过_exit()调用之后会立即进入内核,而exit()函数会先执行一些清理
- MFC中处理消息的几个函数之间的区别
- C++ 中exit(),_exit(),return,abort()函数的区别
- C++中abort()函数与exit()函数区别
- exit()与_exit()函数的区别(Linux系统中)
- 静态和非静态成员,函数之间到底区别在哪里了?
- exit、return、_exit、_Exit这几个函数的区别
- exit、return、_exit、_Exit这几个函数的区别
- 函数声明和函数表达式之间的区别
- 几种窗口销毁函数之间的区别
- exit()与_exit()函数的区别
- C语言中 malloc,calloc 和 realloc 函数之间的区别
- 引用 exit、return、_exit、_Exit这几个函数的区别
- php isset函数对比empty函数之间的区别及其使用方法
- 类成员函数的重载、覆盖与隐藏之间的区别总结
- 让我们来比较C#,C++和Java之间重写虚函数的区别