signalfd_siginfo结构中的ssi_code有什么用?

发布于 2024-12-08 18:10:05 字数 274 浏览 0 评论 0原文

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

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

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

I am using signalfd() to monitor the death of child processes created by my process. If I kill a child process with a signal, parent gets a read event on the signal fd with signalfd_siginfo structure populated. It has a field ssi_code which is set to the signal number the child received (for example 9 if I sent SIGKILL to the child).

Can I rely on this behavior always ? All versions of Linux kernel where signalfd is supported has the same usage for this field ?

Note: If the child calls exit() then the code passed to exit is populated in ssi_code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲墙角沉默 2024-12-15 18:10:05

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 它说:

并非返回的 signalfd_siginfo 结构中的所有字段都对特定信号有效;可以确定有效字段集
来自 ssi_code 字段中返回的值。该字段是
siginfo_t si_code 字段的模拟;详细信息请参见 sigaction(2)。

有关此代码的更多详细信息,请参阅 sigaction 手册 页面,该代码是不是信号编号。

man page of signalfd states :

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) */
           };

It seems clear : ssi_signo contains the signal number. It says about ssi_code that :

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.

See sigaction man page for more details about this code which is not the signal number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文