Linux的sigaction函数与信号相关基础问题

我是小白哈哈哈
  • 96

image.png
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.
本萌新实在不太懂第三个参数是做什么用的,还有它是什么,求大佬们指点

评论
阅读 707
1 个回答

第三个参数是ucontext_t*,是接收到信号时程序执行的上下文,也就是一堆寄存器。有什么用得看场景发挥

void hand(int sig, siginfo_t *info, void *context){
    ucontext_t *ucon = (ucontext_t*)context;
    void *eip = (void*)((struct sigcontext*)(&ucon->uc_mcontext.gregs))->eip;
    printf("sig at eip %p\n",eip);
}
撰写回答

登录后参与交流、获取后续更新提醒

宣传栏