gpt4 book ai didi

c - siginfo 中的 si_int 是什么以及它如何影响信号传播

转载 作者:太空宇宙 更新时间:2023-11-03 23:37:12 25 4
gpt4 key购买 nike

作为向用户空间发送中断的一部分,我看到了以下代码片段,但我不明白 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);
[...]
}

最佳答案

我认为 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 的数据类型。

关于c - siginfo 中的 si_int 是什么以及它如何影响信号传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56588485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com