- 论坛徽章:
- 0
|
20可用积分
写了一个daemon的demo,编译后run了一下,
发现程序直接退出了.gdb调试后发现setsid()返回-1了
上代码:
- #include <fcntl.h>
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/stat.h>
- #include <time.h>
- #include <unistd.h>
- void InitDaemon()
- {
- pid_t chdPid;
- int fd;
- time_t tm;
-
- chdPid = fork();
- if( 0 == chdPid )
- {
- exit( EXIT_SUCCESS );
- }
- if( -1 == chdPid )
- {
- perror( "fork error:\n" );
- exit( EXIT_FAILURE ) ;
- }
- if( -1 == setsid() )
- {
- perror( "setsid err:\n" );
- exit( EXIT_FAILURE );
- }
- ...
- }
复制代码
错误信息:
setsid err:
: Operation not permitted
权限不够?
我是以root运行的.
谁知道是什么原因了?先谢谢了!!! |
最佳答案
查看完整内容
exit()用错地方了 应该结束父进程 setsid()在进程本身就是会话组长时会失败[ 本帖最后由 SNYH 于 2009-11-2 22:59 编辑 ]
|