2012-07-23 13:41:13| 分类: Linux | 标签:linux |字号大中小订阅
比较一下下面三段程序:
程序1
int main()
{ printf("this is a test\n")
printf("test exit fun");
exit(0);
}
运行结果是:
This is a test
Test exit fun[root@localhost3.23]#
程序2
int main()
{ printf("this is a test\n")
printf("test exit fun");
_exit(0);
}
运行结果是:
This is a test
[root@localhost 3.23]#
程序3
int main()
{ printf("this is a test ")
printf("test exit fun\n ");
_exit(0);
}
运行结果是:
This is a testtest exit fun
[root@localhost 3.23]#
用程序1和程序2可以看处exit()和_exit()的区别前者退出后会去刷新缓冲区后者不会故后者后面的test exit fun不会显示其原因可从程序2和3中找到因为printf在终端是行缓冲的即一行结束了才会区刷新缓冲区并输出第二程序中的test exit fun后没有\n故其显示不出来若改为3则就能显示了.