3 ms·
Is there a full and complete example of how to properly handle signals in a multi-threaded program that does the usual stuff (talk to disk, talk on the network)
by ansible 5y ago
Is there a full and complete example of how to properly handle signals in a multi-threaded program that does the usual stuff (talk to disk, talk on the network)? Written in plain C?
I think I know everything that I'm supposed to do (on Linux, for example). But I wouldn't mind looking through an example that handles everything correctly. Something that is designed as an example, as opposed to reading through some much larger and older project.
- pjmlp 5y agoIt is very hard to do it properly in correct way, given how OS specific and underspecified their behaviour is. The easiest way is just to set a variable to mark the occurrence of a signal and nothing else. Then check for changes from other parts of the program. Also be sure to check every C library error result and the value that it was interrupted by signal occurrence, and eventually retry if needed.