exit()和_exit()的比较(与前一篇日志行缓冲区有关)

 

2012-07-23 13:41:13|  分类: Linux |  标签:linux  |字号订阅

 
 

比较一下下面三段程序:

程序1

int main()

{ printf("this is a test ")

printf("test exit fun");

exit(0);

}

运行结果是:

This is a test

Test exit fun[root@localhost3.23]#

程序2

int main()

{ printf("this is a test ")

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 ");

_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后没有 故其显示不出来若改为3则就能显示了.

 
 
 
原文地址:https://www.cnblogs.com/siguoya/p/3512068.html