Chinaunix首页 | 论坛 | 博客
  • 博客访问: 359520
  • 博文数量: 168
  • 博客积分: 6895
  • 博客等级: 准将
  • 技术积分: 1726
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-12 23:01
文章分类

全部博文(168)

文章存档

2011年(6)

2010年(162)

我的朋友

分类: LINUX

2010-10-12 21:07:22

    Hi friend, some interesting came today. see following.
exit.c
#include
#include
#include
#include

int main( int argc, char **argv, char **environ )
{
    pid_t    pid;

    if( 0 > ( pid = fork() ) )
    {
        printf( "fork error!\n" );

        return( false );
    }
    else
    {
        if( pid > 0 )
        {
            printf( "parent pid is %d\n", getpid() );

            exit( EXIT_SUCCESS );
        }

//      sleep( 1 );

        printf( "init pid is %d\n", getppid() );
    }

    return( false );
}
print result:
init pid is 20999
parent pid is 20999

when i turn exit() to _exit(),result is following:
parent pid is 21244
init pid is 1

theory:
1, exit() can do something extra, like clear buffer.
2,  Function _exit() is faster than exit(). _exit() do nothing when it is called.

It is so interesting, isn't it!!!

In fact, If u want to know the basic theory, you should study the gnu/linux source!

阅读(370) | 评论(1) | 转发(0) |
0

上一篇:10 11

下一篇:10 13

给主人留下些什么吧!~~

chinaunix网友2010-10-13 20:24:00

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com