首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么sigaction处理程序中的上下文是一个空指针?

为什么sigaction处理程序中的上下文是一个空指针?
EN

Stack Overflow用户
提问于 2018-08-02 00:11:28
回答 1查看 734关注 0票数 3

sigaction(2)手册页中:

代码语言:javascript
复制
The siginfo_t argument to a SA_SIGINFO handler
   When the SA_SIGINFO flag is specified in act.sa_flags, the signal
   handler address is passed via the act.sa_sigaction field.  This han‐
   dler takes three arguments, as follows:

       void
       handler(int sig, siginfo_t *info, void *ucontext)
       {
           ...
       }

当手册页声明它是一个void *时,它为什么是一个ucontext_t *

代码语言:javascript
复制
ucontext
          This is a pointer to a ucontext_t structure, cast to void *.
          The structure pointed to by this field contains signal context
          information that was saved on the user-space stack by the ker‐
          nel; for details, see sigreturn(2).  Further information about
          the ucontext_t structure can be found in getcontext(3).  Com‐
          monly, the handler function doesn't make any use of the third
          argument.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-02 00:58:55

POSIX实际上要求这是一个void *sigaction的第三个参数是:

代码语言:javascript
复制
void(*) (int, siginfo_t *, void *)

此外,由于void *可以自由地与任何其他类型的数据指针相互转换,所以没有理由不使用一般情况,因为将来您可能希望无缝地添加不同的类型。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51643861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档