Categorically speaking, I suggest that such timeout-handlers should only set a global flag that is tested by the various main-program loops. When the flag becomes raised, the programs break out of their loops. I consider it hazardous to attempt to do actual cleanup processing – closing file-handles and so forth – within such a handler because you really don’t know the exact instance at which the signal arrived. Programs that randomly crash when interrupted ... sometimes, but never when you are trying to debug them ... are the usual symptom of this kind of design. If you follow my suggestion, you know that the program will always stop “at a good stopping place,” leaving the internal state of the system always-good.