gpt4 book ai didi

linux-kernel - ssi_code在signalfd_siginfo结构中有什么用?

转载 作者:行者123 更新时间:2023-12-04 06:11:46 27 4
gpt4 key购买 nike

我正在使用 signalfd() 来监视我的进程创建的子进程的死亡。如果我用信号杀死一个子进程,父进程会在信号 fd 上获得一个读取事件,并填充了 signalfd_siginfo 结构。它有一个字段 ssi_code ,该字段设置为 child 收到的信号编号(例如,如果我向 child 发送了 SIGKILL,则为 9)。

我可以一直依赖这种行为吗?支持 signalfd 的所有 Linux 内核版本对该字段的用法都相同吗?

注意:如果子进程调用 exit(),则传递给 exit 的代码会填充到 ssi_code 中。

最佳答案

signalfd 的手册页指出:

The format of the signalfd_siginfo structure(s) returned by read(2)s from a signalfd file descriptor is as follows:

struct signalfd_siginfo {
uint32_t ssi_signo; /* Signal number */
int32_t ssi_errno; /* Error number (unused) */
int32_t ssi_code; /* Signal code */
uint32_t ssi_pid; /* PID of sender */
uint32_t ssi_uid; /* Real UID of sender */
int32_t ssi_fd; /* File descriptor (SIGIO) */
uint32_t ssi_tid; /* Kernel timer ID (POSIX timers)
uint32_t ssi_band; /* Band event (SIGIO) */
uint32_t ssi_overrun; /* POSIX timer overrun count */
uint32_t ssi_trapno; /* Trap number that caused signal */
int32_t ssi_status; /* Exit status or signal (SIGCHLD) */
int32_t ssi_int; /* Integer sent by sigqueue(2) */
uint64_t ssi_ptr; /* Pointer sent by sigqueue(2) */
uint64_t ssi_utime; /* User CPU time consumed (SIGCHLD) */
uint64_t ssi_stime; /* System CPU time consumed (SIGCHLD) */
uint64_t ssi_addr; /* Address that generated signal
(for hardware-generated signals) */
uint8_t pad[X]; /* Pad size to 128 bytes (allow for
additional fields in the future) */
};

似乎很清楚: ssi_signo 包含信号编号。它说 ssi_code :

Not all fields in the returned signalfd_siginfo structure will be valid for a specific signal; the set of valid fields can be determined from the value returned in the ssi_code field. This field is the analog of the siginfo_t si_code field; see sigaction(2) for details.



sigaction man有关此代码的更多详细信息,请访问 不是 信号编号。

关于linux-kernel - ssi_code在signalfd_siginfo结构中有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7692364/

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