in reply to sleep and waking on signal handlers
...or are you on Windows, where signals are only partially emulated? You might have better luck with SetConsoleCtrlHandler.