2 ms·
Hey, this is a really neat idea -- thanks for sharing. Take special care to review the "Async-signal-safe functions" section of signal(7) [1]. Some of the fun
by wyldfire 10y ago
Hey, this is a really neat idea -- thanks for sharing.
Take special care to review the "Async-signal-safe functions" section of signal(7) [1]. Some of the functions you're using in your signal handler aren't safe to be used there. If you want to still have a correct example of this feature you should focus on narrowing your handler down to something extremely minimal. For example, some enumeration representing the program state stored as a sig_atomic_t. You can write to it in the handler. If you don't like polling the sig_atomic_t you can use the write-to-your-own-pipe trick [2].
[1] http://man7.org/linux/man-pages/man7/signal.7.html http://man7.org/linux/man-pages/man7/signal.7.html
[2] https://www.sitepoint.com/the-self-pipe-trick-explained/ https://www.sitepoint.com/the-self-pipe-trick-explained/