#include "csapp.h"
#include "sio_printf.h"

void sigint_handler(int sig)
{
    // The Sio_* functions are safe to call from a signal handler.
    Sio_printf("Process %d received signal %d, exiting.\n",
               (int) getpid(), sig);

    // exit() is not safe to call from a signal handler, but _exit() is.
    _exit(0);
}

int main(void)
{
    struct sigaction sa;
    // Sensible defaults. Use these unless you have a reason not to.
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    // The handler for SIGINT will be sigint_handler.
    sa.sa_handler = sigint_handler;
    if (sigaction(SIGINT, &sa, 0) != 0)
      unix_error("signal error");

    // Wait for the receipt of a signal.
    pause();

    puts("This message will never be printed (do you see why?)");
    return 1;
}
