本文共 517 字,大约阅读时间需要 1 分钟。
#include "pch.h"#include#include #include 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;}
参考