简体   繁体   English

signal()有什么作用?

[英]What does signal() do?

http://linux.die.net/man/2/signal http://linux.die.net/man/2/signal

"signal() sets the disposition of the signal signum to handler, which is either SIG_IGN, SIG_DFL, or the address of a programmer-defined function (a "signal handler")." “ signal()将信号符号的设置设置为处理程序,该处理程序可以是SIG_IGN,SIG_DFL或程序员定义的函数的地址(“信号处理程序”)。

I find the description of what it does to be vague (new to network and linux programming). 我发现它的模棱两可的描述(网络和linux编程的新手)。 Is this some sort of callback setting function? 这是某种回调设置功能吗? Right now my code (which I haven't compiled yet) is using it like: 现在,我的代码(尚未编译)正在像这样使用它:

signal( SIGIO, readMessage );

Where readMessage is a function. 其中readMessage是一个函数。 SIGIO is defined as: SIGIO定义为:

SIGPOLL is the signal sent to a process when an asynchronous I/O event occurs. SIGPOLL是异步I / O事件发生时发送到进程的信号。

So putting this all together, I can only guess that when some asynchronous I/O event occurs, the function readMessage( int ) is called? 因此,将所有这些放在一起,我只能猜测,当发生一些异步I / O事件时,将调用readMessage(int)函数吗? Is this like slots/signals in Qt? 这就像Qt中的广告位/信号吗?

One other question I have is, what exactly is considered an I/O event in the context of network programming? 我还有一个问题是,在网络编程的背景下,什么才算是I / O事件? Is it an accept call that returns? 返回的接受呼叫吗?

On *nix, signals are callbacks from the kernel to userspace. 在* nix上,信号是从内核到用户空间的回调。 They are somewhat similar to interrupts, which can be thought of as callbacks from the hardware to the operating system. 它们有点类似于中断,可以将其视为从硬件到操作系统的回调。

They are more alike events in event-based systems than signals/slots in Qt. 在基于事件的系统中,它们比在Qt中的信号/时隙更像事件。 In Qt, a component can emit signals, which can be received by several slots in other components, and the program sets the connections between signals and slots, In other systems (Xlib, Win32), the program receives predetermined events from the system. 在Qt中,一个组件可以发出信号,该信号可以被其他组件中的多个插槽接收,并且该程序设置信号和插槽之间的连接。在其他系统(Xlib,Win32)中,该程序从系统接收预定的事件。

*nix supports blocking and non-blocking sockets. * nix支持阻塞和非阻塞套接字。 The poll() and select() system calls allow a program to wait for an I/O event. poll()select()系统调用允许程序等待I / O事件。 As an alternative to poll() / select() , BSD and Linux can also be made to send a signal (SIGIO by default) when an I/O event occurs, achieving a form of asynchronous I/O. 作为poll() / select()的替代方法,还可以使BSD和Linux在发生I / O事件时发送信号(默认情况下为SIGIO),从而实现一种异步I / O形式。 More information can be found in the manpage for fcntl() , looking for F_SETFL , F_SETOWN , F_SETSIG . 可以在fcntl()的联机帮助页中找到更多信息,以查找F_SETFLF_SETOWNF_SETSIG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM