免费注册 查看新帖 |

Chinaunix

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

信号可靠还是不可靠,取决与信号本身还是signal()/sigaction()的区别? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-22 09:01 |只看该作者 |倒序浏览
1-31号信号,不支持排队,会丢失,所以是不可靠信号,即使用sigaction函数系列来处理也不行?

是不是说,"可靠"和"不可靠"是按照信号的数字来划分的,34-64是可靠信号。
可靠信号不论用signal函数来处理还是用sigaction来处理,都是"可靠的",不会丢失不会有什么问题?

但是为什么有很多人又说,可靠和不可靠的区分,不是在于信号本身,而是在于signal/sigaction的区别呢?

我很疑惑了,请指点指点我哈!

论坛徽章:
11
未羊
日期:2013-12-16 12:45:4615-16赛季CBA联赛之青岛
日期:2016-04-11 19:17:4715-16赛季CBA联赛之广夏
日期:2016-04-06 16:34:012015亚冠之卡尔希纳萨夫
日期:2015-11-10 10:04:522015亚冠之大阪钢巴
日期:2015-07-30 18:29:402015亚冠之城南
日期:2015-06-15 17:56:392015亚冠之卡尔希纳萨夫
日期:2015-05-15 15:19:272015亚冠之山东鲁能
日期:2015-05-14 12:38:13金牛座
日期:2014-12-04 15:34:06子鼠
日期:2014-10-16 13:40:4715-16赛季CBA联赛之八一
日期:2016-07-22 09:41:40
2 [报告]
发表于 2012-03-22 09:45 来自手机 |只看该作者
按数字划分
signal  和 sigaction  区别在于, 即便信号是可靠的, 信号处理函数是不可靠的。

论坛徽章:
0
3 [报告]
发表于 2012-03-22 10:01 |只看该作者
zylthinking 发表于 2012-03-22 09:45
按数字划分
signal  和 sigaction  区别在于, 即便信号是可靠的, 信号处理函数是不可靠的。


是不是说,sigaction处理1-31号信号,也是不可靠的。

(1)除非可靠信号+sigaction,加一起才是可靠的过程。
(2)POSIX的信号1-31这些,无论如何处理都是不可靠的,用signal/sigaction来处理效果一样,是么?

第(2)点有没有错误?

论坛徽章:
11
技术图书徽章
日期:2014-03-01 14:44:34天蝎座
日期:2014-05-21 22:11:59金牛座
日期:2014-05-30 17:06:14
4 [报告]
发表于 2012-03-22 12:07 |只看该作者
还在纠结信号可靠与否吗?早就被丢进垃圾堆的东西了!
请先从APUE看下什么叫可靠信号,信号排队与否是区别普通信号(1-31)与实时信号(SIGRTMIN-SIGRTMAX)的依据,而不是区分信号可靠与否的依据。

当前UNIX(IBM AIX, HP UX, Oracle Solaris, Mac os X)/Linux都已实现了可靠信号,即使signal本身都是用sigaction实现的,只是POSIX标准要求sigaction必定要实现可靠信号语义,所以sigaction移植性更好

论坛徽章:
11
未羊
日期:2013-12-16 12:45:4615-16赛季CBA联赛之青岛
日期:2016-04-11 19:17:4715-16赛季CBA联赛之广夏
日期:2016-04-06 16:34:012015亚冠之卡尔希纳萨夫
日期:2015-11-10 10:04:522015亚冠之大阪钢巴
日期:2015-07-30 18:29:402015亚冠之城南
日期:2015-06-15 17:56:392015亚冠之卡尔希纳萨夫
日期:2015-05-15 15:19:272015亚冠之山东鲁能
日期:2015-05-14 12:38:13金牛座
日期:2014-12-04 15:34:06子鼠
日期:2014-10-16 13:40:4715-16赛季CBA联赛之八一
日期:2016-07-22 09:41:40
5 [报告]
发表于 2012-03-22 12:47 来自手机 |只看该作者
效果不一样, sigaction 可以保证处理函数的可靠, signal 不保证, 我觉得你其实是明白这个的。 因此处理效果是不一样的。 其余的我觉得你理解没问题

论坛徽章:
0
6 [报告]
发表于 2012-03-22 13:28 |只看该作者
回复 4# timespace


这位兄弟说的对。

      Real-time signals are distinguished by the following:

       1.  Multiple  instances  of real-time signals can be queued.  By contrast, if multiple instances of a standard signal are
           delivered while that signal is currently blocked, then only one instance is queued.

       2.  If the signal is sent using sigqueue(2), an accompanying value (either an integer or a pointer) can be sent with  the
           signal.   If  the  receiving  process establishes a handler for this signal using the SA_SIGINFO flag to sigaction(2)
           then it can obtain this data via the si_value field of the siginfo_t structure passed as the second argument  to  the
           handler.   Furthermore, the si_pid and si_uid fields of this structure can be used to obtain the PID and real user ID
           of the process sending the signal.

       3.  Real-time signals are delivered in a guaranteed order.  Multiple real-time signals of the same type are delivered  in
           the order they were sent.  If different real-time signals are sent to a process, they are delivered starting with the
           lowest-numbered signal.  (I.e., low-numbered signals have highest priority.)  By contrast, if multiple standard  sig-
           nals are pending for a process, the order in which they are delivered is unspecified.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP