Answers for "launch function with signal c++"

C++
0

launch function with signal c++

#include <iostream>
#include <csignal>
 
using namespace std;

sig_atomic_t signalled = 0;

void handler(int sig)
{
    signalled = 1;
}

int main()
{
    signal(SIGINT, handler);
    
    raise(SIGINT);
    if (signalled)
        cout << "Signal is handled";
    else
        cout << "Signal is not handled";

    return 0;
}
Posted by: Guest on October-09-2020

Browse Popular Code Answers by Language