另外参见

timer_create(2),aio_fsync(3),aio_read(3),aio_write(3),getaddrinfo_a(3),lio_listio(3),mq_notify(3),aio(7),pthreads(7)

说明

各种API使用sigevent结构来描述有关事件的流程通知方式(例如,异步请求的完成,计时器的到期或消息的到达)。

概要中显示的定义是近似的:sigevent结构中的某些字段可以定义为联合的一部分。程序应仅使用与sigev_notify中指定的值相关的那些字段。

sigev_notify字段指定如何执行通知。该字段可以具有以下值之一:

SIGEV_NONE
"空"通知:事件发生时不执行任何操作。
SIGEV_SIGNAL
通过发送sigev_signo中指定的信号来通知该过程。
If the signal is caught with a signal handler that was registered using the sigaction(2)

SA_SoirNFO

flag, then the following fields are set in the
soirnfo_t

structure that is passed as the second argument of the handler:

si_code
此字段设置为取决于传递通知的API的值。
si_signo
此字段设置为信号编号(即与sigev_signo中的值相同)。
si_value
该字段设置为sigev_value中指定的值。
根据API,还可以在soirnfo_t结构中设置其他字段。
如果使用sigwaitinfo(2)接受信号,则也可以使用相同的信息。
SIGEV_THREAD
通过"好像"调用sigev_notify_function来通知该进程,它就像是新线程的启动函数。 (在这里可能的实现方式是,每个计时器通知都可能导致创建新线程,或者创建了一个线程来接收所有通知。)使用sigev_value作为其唯一参数调用该函数。如果sigev_notify_attributes不为NULL,则它应指向pthread_attr_t结构,该结构定义新线程的属性(请参阅pthread_attr_init(3))。
SIGEV_THREAD_ID(Linux-specific)
当前仅由POSIX计时器使用;参见timer_create(2)。

语法

#include <signal.h>

union sigval {          /* Data passed with notification */
    int     sival_int;         /* Integer value */
    void   *sival_ptr;         /* Pointer value */
};

struct sigevent {
    int          sigev_notify; /* Notification method */
    int          sigev_signo;  /* Notification signal */
    union sigval sigev_value;  /* Data passed with
                                  notification */
    void       (*sigev_notify_function) (union sigval);
                     /* Function used for thread
                        notification (SIGEV_THREAD) */
    void        *sigev_notify_attributes;
                     /* Attributes for notification thread
                        (SIGEV_THREAD) */
    pid_t        sigev_notify_thread_id;
                     /* ID of thread to signal (SIGEV_THREAD_ID) */
};
SIGEVENT - Linux手册页

Linux程序员手册 第7部分
更新日期: 2020-04-11

出版信息

这个页面是Linux手册页项目5.08版的一部分。有关项目的说明、有关报告错误的信息以及此页面的最新版本,请访问https://www.kernel.org/doc/man-pages/

名称

sigevent-用于从异步例程进行通知的结构

日期:2019-08-20 18:02:02 来源:oir作者:oir