开发者

What is the use of ssi_code in signalfd_siginfo structure?

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 sig开发者_开发百科nalfd_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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜