Answers for "linux c++ sigint handler"

C++
0

linux c++ sigint handler

#include <signal.h>
#include <iostream>
#include <thread>
#include <chrono>

void sigint_handler(int signo) {
    if (signo == SIGINT) {
        printf("received SIGINT, aborting abruptly\n");
        abort();
    }
}

int main() {
    signal(SIGINT, sigint_handler);
    while (true) {
        std::cout << "Loop..." << std::endl;
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
    }
}
Posted by: Guest on February-28-2022

Browse Popular Code Answers by Language