linux进程控制编程-exit()和_exit()函数区别
linux进程控制编程,通过程序分析-exit()和_exit()函数区别
代码分析
程序分析
//exit() _exit function
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
//#include <stdlib.h>
//void exit(int status);
//#include <unistd.h>
//void _exit(int status);
int main()
{
if ((fork()) == 0 )
{
printf("This is child process Using exit\n");
printf(" Print content in child buff ");
exit(0);
}
else
{
sleep(1);
printf("This is father process Using _exit\n");
printf(" Print content in father buff ");
_exit(0);
}
}
执行结果
因为下面“print content…”这句话没有\n,则不会被直接输出,会先存放到缓冲区。而exit()函数在退出的时候会把缓冲区内容写回,但是_exit()函数则会直接退出,不做收尾工作,因此会出现如图结果。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 不听话的兔子君!