在向用户空间发送中断的过程中,我看到了以下代码片段,但我不了解si_int
如何影响信号传播。
static int SendToUsrSpace(void) {
struct siginfo info;
struct task_struct *t;
int ret;
memset(&info, 0, sizeof(struct siginfo));
info.si_signo = 44;
info.si_code = SI_QUEUE;
info.si_int = 1234; // WHY NOT 36 or any random number?
[...]
ret = send_sig_info(44, &info, t);
[...]
}
答案 0 :(得分:1)
我认为explanation is in sigqueue(3)。从文本中:
sigqueue() sends the signal specified in sig to the process whose PID
is given in pid. The permissions required to send a signal are the
same as for kill(2). As with kill(2), the null signal (0) can be
used to check if a process with a given PID exists.
The value argument is used to specify an accompanying item of data
(either an integer or a pointer value) to be sent with the signal,
and has the following type:
union sigval {
int sival_int;
void *sival_ptr;
};
If the receiving process has installed 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_code field of
that structure will be set to SI_QUEUE.
因此,1234看起来像一个进程可以拉出的任意值(如果它具有此信号的处理程序)。看起来像一种通过信号发送数据的方式。
其他阅读:我从sigaction(2)到达sigqueue,它列出了siginfo_t的数据类型。