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!
阅读(372) | 评论(1) | 转发(0) |