免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3333 | 回复: 12
打印 上一主题 下一主题

[C++] 怪哉,服务程序悄无声息的退出 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-30 12:09 |只看该作者 |倒序浏览
本帖最后由 fly6 于 2012-07-30 12:10 编辑

程序启动时就下注册了如下信号,并在信号自理程序中打印了日志。
if((sigaction(SIGILL, &struAct, NULL) != 0) ||
           (sigaction(SIGSEGV, &struAct, NULL) != 0) ||
           (sigaction(SIGBUS, &struAct, NULL) != 0))
        {
                cutil_log_error("install sigaction catch error:%s\n", cutil_get_error(-1));
                return -1;
        }

程序主循环,这是一个死循环
while(1)
{
  do_some_thing();
}

按理说程序要退出,除非异常退出,奇怪的是并没有输出异常信息。(程序不会接收到SIGKILL,SIGQUIT)
请问还有什么会令程序退出不打印异常信息

论坛徽章:
2
CU大牛徽章
日期:2013-04-17 11:46:28CU大牛徽章
日期:2013-04-17 11:46:39
2 [报告]
发表于 2012-07-30 13:04 |只看该作者
正常退出,貌似不会打印吧

论坛徽章:
0
3 [报告]
发表于 2012-07-30 13:15 |只看该作者
这是个死循环,不会正常退出的

论坛徽章:
7
荣誉版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07狮子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10双子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
4 [报告]
发表于 2012-07-30 13:46 |只看该作者
猜一下,是不是tty没关闭?
其实守护进程就那么几个要点,弄个check list挨个查一遍就找到原因了。

论坛徽章:
0
5 [报告]
发表于 2012-07-30 21:56 |只看该作者
  1. if((sigaction(SIGILL, &struAct, NULL) != 0) ||
  2.            (sigaction(SIGSEGV, &struAct, NULL) != 0) ||
  3.            (sigaction(SIGBUS, &struAct, NULL) != 0))
  4.         {
  5.                 cutil_log_error("install sigaction catch error:%s\n", cutil_get_error(-1));
  6.                 return -1;
  7.         }

复制代码
你这只是信号注册部分吧,相应的信号处理函数是什么样的...............

论坛徽章:
0
6 [报告]
发表于 2012-07-30 22:29 |只看该作者
回复 4# r2007
这个在程序一开始就做了demon处理,包括关闭tty,关闭会话,还有fork

     

论坛徽章:
0
7 [报告]
发表于 2012-07-30 22:31 |只看该作者
回复 5# Moon_Bird
就是打印错误信息及堆栈信息


   

论坛徽章:
7
荣誉版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07狮子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10双子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
8 [报告]
发表于 2012-07-31 01:44 |只看该作者
FYI
The common method for a process to become a daemon involves:

    Dissociating from the controlling tty
    Becoming a session leader
    Becoming a process group leader
    Executing as a background task by forking and exiting (once or twice). This is required sometimes for the process to become a session leader. It also allows the parent process to continue its normal execution.
    Setting the root directory ("/") as the current working directory so that the process does not keep any directory in use that may be on a mounted file system (allowing it to be unmounted).
    Changing the umask to 0 to allow open(), creat(), et al. operating system calls to provide their own permission masks and not to depend on the umask of the caller
    Closing all inherited files at the time of execution that are left open by the parent process, including file descriptors 0, 1 and 2 (stdin, stdout, stderr). Required files will be opened later.
    Using a logfile, the console, or /dev/null as stdin, stdout, and stderr

论坛徽章:
208
巨蟹座
日期:2013-09-02 09:16:36卯兔
日期:2013-09-02 20:53:59酉鸡
日期:2013-09-05 21:21:45戌狗
日期:2013-10-15 20:51:17寅虎
日期:2013-10-18 21:13:16白羊座
日期:2013-10-23 21:15:19午马
日期:2013-10-25 21:22:48技术图书徽章
日期:2013-11-01 09:11:32双鱼座
日期:2013-11-01 20:29:44丑牛
日期:2013-11-01 20:40:00卯兔
日期:2013-11-11 09:21:32酉鸡
日期:2013-12-04 19:56:39
9 [报告]
发表于 2012-07-31 08:56 |只看该作者
信号不一定能抓到,有些程序都抓SIGSEGV了,还是没提示,直接挂了
多半是exception退出了

论坛徽章:
0
10 [报告]
发表于 2012-07-31 09:03 |只看该作者
嗯,楼上可以再详细点具体点不
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP