sigevent(7) - Linux 手册页
名称
sigevent - 异步例程通知的结构体概要
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 结构体被各种 API 使用来描述如何通知进程某个事件(例如,异步请求完成、定时器到期或消息到达)。
SYNOPSIS 中显示的定义是近似的:sigevent 结构体中的某些字段可能被定义为联合体的一部分。程序应该只使用 sigev_notify 中指定的值相关的字段。
sigev_notify 字段指定如何执行通知。该字段可以具有以下值
- SIGEV_NONE
- “空”通知:事件发生时什么也不做。
- SIGEV_SIGNAL
- 通过发送 sigev_signo 中指定的信号来通知进程。
- 如果信号使用使用 sigaction(2) SA_SIGINFO 标志注册的信号处理程序捕获,则以下字段将在作为处理程序第二个参数传递的 siginfo_t 结构体中设置
- 该字段设置为取决于提供通知的 API 的值。
- si_code
- 该字段设置为信号编号(即,与 sigev_signo 中的值相同)。
- si_signo
- 该字段设置为 sigev_value 中指定的值。
- si_value
- 根据 API,其他字段也可能在
- siginfo_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 特有)
- 当前仅由 POSIX 定时器使用;参见 timer_create(2)。