谁使用POSIX实时信号,为什么? [英] Who uses POSIX realtime signals and why?

查看:211
本文介绍了谁使用POSIX实时信号,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有被翻转,我真的不明白。我只是读了一大堆材料,我无法弄清楚用例。我不是在说这么多关于API的优点,比像signal()这样的优点足够清楚。相反,似乎RT信号是为了生成用户空间而是为了什么目的?唯一的用途似乎是一个原始的IPC,但是所有的东西都指向它们是一个糟糕的IPC形式(例如尴尬,有限的信息,不是特别有效的等等)。



所以

解决方案

首先,请注意,Ben的答案是正确的。据我所知,POSIX中的实时信号的全部目的是作为AIO,消息队列通知,定时器到期和应用定义信号(内部和进程间)的实时传送机制。



这样说,一般来说,信号是一个非常糟糕的做法:




  • 信号处理程序是异步的,除非您确保它们不会中断异步信号不安全功能,否则他们只能使用异步信号安全功能,这真的会削弱他们可以做的。

  • 信号处理程序是全球状态。图书馆无法使用与调用程序签订合同的信号,该协议允许使用哪些信号,无论是否允许使用这些信号进行系统调用中断等。一般来说,全局状态只是一个坏事。

  • 如果您使用 sigwait (或Linux signalfd 扩展名),而不是信号处理程序处理信号,它们不比其他IPC /通知机制更好,但仍然可能更糟。



异步IO很多更好地通过忽略设计不良的POSIX AIO API,并创建一个线程来执行正常的阻塞IO,并调用 pthread_cond_signal sem_post 操作完成。或者,如果您能够承担一点点性能成本,您甚至可以通过管道或套接字将刚刚读取的数据转发回自己,并使主线程异步读取正常文件,使用 select poll 就像你的socket / pipes / ttys一样。


I am not being flip I really don't get it. I just read a whole bunch of material on them and I can't figure out the use case. I am not talking talking so much about the API for which the advantages over things like signal() are clear enough. Rather it seems RT signals are meant to be user space generated but to what end? The only use seems to be a primitive IPC but everything points to them being a lousy form of IPC (e.g. awkward, limited information, not particularly efficient, etc).

So where and how are they used?

解决方案

First of all, note that Ben's answer is correct. As far as I can tell, the whole purpose of realtime signals in POSIX is as a realtime delivery mechanism for AIO, message queue notifications, timer expirations, and application-defined signals (both internal and inter-process).

With that said, signals in general are a really bad way to do things:

  • Signal handlers are asynchronous, and unless you ensure they do not interrupt an async-signal-unsafe function, they can only use async-signal-safe functions, which really cripples what they can do.
  • Signal handlers are global state. A library cannot use signals without a contract with the calling program regarding which signals it's allowed to use, whether it's allowed to make them syscall-interrupting, etc. And in general, global state is just A Bad Thing.
  • If you use sigwait (or Linux signalfd extension) rather than signal handlers to process signals, they're no better than other IPC/notification mechanisms, and still potentially worse.

Asynchronous IO is much better accomplished by ignoring the ill-designed POSIX AIO API and just creating a thread to perform normal blocking IO and call pthread_cond_signal or sem_post when the operation finishes. Or, if you can afford a little bit of performance cost, you can even forward the just-read data back to yourself over a pipe or socketpair, and have the main thread process asynchronously-read regular files with select or poll just like you would sockets/pipes/ttys.

这篇关于谁使用POSIX实时信号,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆