singal.c

来自「linux 下实现信号处理」· C语言 代码 · 共 19 行

C
19
字号
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void catch_int(int sig_num)
{
	// 重新设置 SIGINT 的 handler
	signal(SIGINT, catch_int);
	printf("Control-C is ignored, please don't waste time.\n");
	fflush(stdout);
}
int main(int argc, char* argv[])
{
	//设置Control-C的回调
	printf("Want to try Control-C ?\n");
	signal(SIGINT, catch_int);
	//进入循环
	while(1) 
	pause();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?