Talk:Handle a signal

From Rosetta Code
Revision as of 08:36, 31 March 2009 by Ce (talk | contribs) (Error in C example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Error in C example

The C example uses printf in the signal handler. However, printf isn't signal-safe, that is, if the signal happens during the printf call in the main program, it might fail. The correct way would be to set a flag of type volatile sig_atomic_t in the signal handler, and test that flag in the main program. Note that usleep returns when interrupted by a signal, so handling of that signal will not be delayed that way.