Chinaunix首页 | 论坛 | 博客
  • 博客访问: 399690
  • 博文数量: 83
  • 博客积分: 2011
  • 博客等级: 大尉
  • 技术积分: 741
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-04 22:51
文章分类

全部博文(83)

文章存档

2009年(83)

我的朋友

分类: LINUX

2009-07-25 09:46:42

两函数都是终止进程.
exit() 调用exit 系统调用时, 先调用退出处理函数, 再清理I/O缓冲, 最后才调用exit 系统调用.
而_exit() 直接调用exit 系统调用.
 
对于具有缓冲I/O操作的程序中, 若想保证数据的完整性,就必须用exit() 终止进程.
以下是个简单的例子:
 
#include
#include
#include
#include
int main()
{
 pid_t result;
 
 result = fork();
 if (result == -1)
 {
  perror("creat child process failed");
  exit(1);
 }
 else if (result == 0)
 {
  printf("test exit process function _exit()\n");
  printf("we use cache");
  _exit(0);
 }
 else
 {
  printf("test exit process function exit()\n");
  printf("we use cache");
  exit(0);
 }
}
 
 
[root@localhost process]# ./exit
test exit process function _exit()
test exit process function exit()
we use cache[root@localhost process]#
阅读(1078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~