signal test

This commit is contained in:
LingZhaoHui 2020-08-02 19:28:08 +08:00
parent 08944c8ed0
commit afa981134a
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
jmp_buf buf;
void handler(int s)
{
if (s == SIGINT) printf("now got a SIGINT signal\n");
longjmp(buf, 1);
/* 没有到达 */
}
int main(void)
{
signal(SIGINT, handler);
if (setjmp(buf))
{
printf("back in main \n");
return 0;
}
else
{
printf("first time through\n");
}
loop:
goto loop;
return 0;
}