gpt4 book ai didi

c - 信号处理程序 sa_sigaction 参数

转载 作者:太空宇宙 更新时间:2023-11-04 00:15:31 24 4
gpt4 key购买 nike

我有

struct sigaction pipe_act;
pipe_act.sa_flags = SA_SIGINFO;
pipe_act.sa_sigaction = sigpipehandler
sigaction(SIGPIPE, &pipe_act, NULL);

当我尝试编写 sigpipeHandler 时,gcc 告诉我它需要三个参数。第二个参数没问题,它是包含有关信号的信息的 siginfo_t 结构,第一个和第三个参数(一个 int 和一个 void 变量),它们是什么?

最佳答案

sigaction 的人说:

 The sigaction structure is defined as something like:

struct sigaction {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *, void *);
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
};

sa_handler specifies the action to be associated with signum and may be
SIG_DFL for the default action, SIG_IGN to ignore this signal, or a
pointer to a signal handling function. This function receives the sig‐
nal number as its only argument.

If SA_SIGINFO is specified in sa_flags, then sa_sigaction (instead of
sa_handler) specifies the signal-handling function for signum. This
function receives the signal number as its first argument, a pointer to
a siginfo_t as its second argument and a pointer to a ucontext_t (cast
to void *) as its third argument.


....
   The siginfo_t argument to sa_sigaction is a struct with  the  following
elements:
       siginfo_t {
int si_signo; /* Signal number */
int si_errno; /* An errno value */
int si_code; /* Signal code */
int si_trapno; /* Trap number that caused
hardware-generated signal
(unused on most architectures) */
pid_t si_pid; /* Sending process ID */
uid_t si_uid; /* Real user ID of sending process */
int si_status; /* Exit value or signal */
clock_t si_utime; /* User time consumed */
clock_t si_stime; /* System time consumed */
sigval_t si_value; /* Signal value */
int si_int; /* POSIX.1b signal */
void *si_ptr; /* POSIX.1b signal */
int si_overrun; /* Timer overrun count; POSIX.1b timers */
int si_timerid; /* Timer ID; POSIX.1b timers */
void *si_addr; /* Memory location which caused fault */
long si_band; /* Band event (was int in
glibc 2.3.2 and earlier) */
int si_fd; /* File descriptor */
short si_addr_lsb; /* Least significant bit of address
(since kernel 2.6.32) */
}

关于c - 信号处理程序 sa_sigaction 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12587621/

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