You need to use the signal() call with SIGINT.