两函数都是终止进程.
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]#
阅读(1107) | 评论(0) | 转发(0) |