Add a signal handler to exit gracefully from capture