Windows10 VS2017 C++信号处理

Posted on 2018-12-25 16:44  #大囚长#  阅读(217)  评论(0编辑  收藏  举报
#include "pch.h"
#include <iostream>
#include <csignal>
#include <windows.h>

using namespace std;

int i;

void signalHandle(int signum)
{
	cout << "Interrupt signal(" << signum << ")received" << endl;
	i = signum;
}


int main()
{
	//注册信号以及信号处理程序
	signal(SIGINT, signalHandle);

	while (1)
	{
		if (i == 2)
		{
			break;
		}
		cout << "hello..." << endl;
		Sleep(1000);//暂停1s
	}

	system("pause");
	return 0;
}

参考
https://blog.csdn.net/qq_28796345/article/details/51290493