int daemon()
{
pid_t pid ;
pid = fork () ;
if (pid < 0) {
printf ( "Cannot fork a new process to run in background\n") ;
return -2 ;
}
if (pid > 0) { /* parent process */
printf ( "NewMailNotify is now runing in background.\n" ) ;
exit (0) ;
}
setsid () ;
return 0 ;
}
int main()
{
daemon();
....
}
Linux 程序后台运行的简单方法
最新推荐文章于 2025-07-01 22:59:43 发布