Windows10 VS2017 C++訊號處理

大囚長發表於2018-12-25
#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

相關文章