umask( 0 );
return 0;
}
if( (pid = fork()) < 0 )
{
fprintf(stderr, "fork err!\n");
return -1;
}
else if( pid > 0 )
{
fprintf( stderr, "结束进程[%d]\n", getpid() );
exit( 0 );
}
fprintf( stderr, "孤儿进程[%d]\n", getpid() );
signal( SIGHUP, SIG_IGN );
signal( SIGQUIT, SIG_IGN );
signal( SIGCHLD, SIG_IGN );
setsid();
umask( 0 );
return 0;
}
原文地址:http://blog.csdn.net/ssz912728941/article/details/34106555