知道为什么信号处理程序会进入无限循环吗?
这是代码.请帮我.
enter code here
9 void SIGSEGV_handler(int signal)
10 {
11 printf("Segmentation fault caught....\n");
12 printf("Value of instance variable: i = %d\n\n", i);
13 }
16
17 int main()
18 {
19 char *mallocPtr, *callocPtr, *reallocPtr, *memalignPtr, *vallocPtr;
20 struct sigaction sa;
21
22 sa.sa_handler=SIGSEGV_handler;
23 sigaction(SIGSEGV, &sa, NULL);
24
37
38 printf("The segmentation fault handler will be entered for i = 3, 4, 5 and 6\n");
39
40
41 for(i=0; i<7; i++)
42 {
43 printf("i = %d\n",i); …Run Code Online (Sandbox Code Playgroud) 我使用sigsetjmp和siglongjmp编写了一个分段错误处理程序.一旦它进入信号处理程序,我调用siglongjmp,以便跳过错误的指令.
问题是,我再次想要导致SIGSEGV并转到相同的处理程序,但现在sigsetjmp将返回1.
如何重置sigsetjmp?
这是我的代码:
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h>
#include <setjmp.h>
sigjmp_buf env, env1;
void SIGSEGV_handler(int signal)
{
printf("Segmentation fault caught\n");
siglongjmp(env, 1);
}
int main()
{
void * allocation;
size_t size;
static int devZerofd = -1;
struct sigaction sa, sa1;
sa.sa_handler=(void*)SIGSEGV_handler;
sigaction(SIGSEGV, &sa, NULL);
if ( devZerofd == -1 ) {
devZerofd = open("/dev/zero", O_RDWR);
if ( devZerofd < 0 )
perror("open() on /dev/zero failed");
}
allocation = …Run Code Online (Sandbox Code Playgroud)