/*
    this program demonstrates how a program can capture a ^C at the 
    command prompt


*/

#include <signal.h>
#include <assert.h>
#include <iostream>
using namespace std;

void sigint_handler(int signum)
{
    // put code here that you want executed before program exits
    cout << "sig_handler received signum = " << signum << endl;
}

int main()
{
    // SIGINT is the interrupt signal
    // it is passed to the program when user types ^C at command prompt
    assert(signal(SIGINT, sigint_handler) != SIG_ERR);

    cout << "main() going to sleep" << endl;
    cout << "^C to see what happens" << endl;
    sleep(1000);
}

