函数exit与_exit的区别

 

 

/****************************************
*文件名:exit_differ.c
*描述:比较函数exit(int status)与函数_exit(int status)的区别
*    #include <stdlib.h>
*    void exit(int status)
*    void _exit(int status)
*    区别:exit函数在调用之前要检查文件的打开情况,
*          把文件缓冲区的内容写会文件;而_exit直接使进程
*          停止运行,清除其使用的内存空间,并销毁起在内核
*          中的各种数据结构   
********************************************/

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#define OK 0

int main( void )
{
    pid_t pid;
    pid = fork();

    if ( -1 == pid )
    {
        printf("failed to create a new process!\n");
        exit(0);
    }else if ( 0 == pid )
    {
        printf("child process,output begin!\n");
        printf("child process,content in buffer!");
        exit(0);
    }else
    {
        printf("\nparent process,output begin\n");
        printf("parent process, content in buffer");
        _exit(0);
    }
   
    return OK;
}

 

child process,output begin!
child process,content in buffer!
parent process,output begin
 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值