OCaml printing isn't printf in C - it calls directly write() and is always possible. OCaml signal handlers aren't signal handlers from the C viewpoint: When the signal is caught, a flag in the OCaml runtime is set, and this flag is regularly checked by the running code. (I.e. what you suggest is already done in the runtime.) So, I'd say this is a bug in the OCaml runtime. The bug goes away when you print to a different channel from the signal handler, so it looks like channels and signal handlers have some unwanted effect on each other. Gerd Am Mittwoch, den 19.03.2014, 23:19 +0100 schrieb Jesper Louis Andersen: > > On Wed, Mar 19, 2014 at 10:21 PM, Anders Peter Fugmann > wrote: > Is printing from a signal handler illegal? > > FWIW, that is illegal in some operating systems. I have seen it in one > case at least: > > > * Linux with threads. printf in C is protected by a mutex. Suppose we > are inside the printf, with the mutex locked and then we get a signal. > We run the handler, and it wants to print out debug information. > Welcome deadlock! > * Many system calls are not safe in the signal handler. FreeBSD has a > list in sigaction(2) for instance. See > > > > http://www.freebsd.org/cgi/man.cgi?query=sigaction&apropos=0&sektion=0&manpath=FreeBSD+10.0-RELEASE&arch=default&format=html > > > In practice, you should probably just set a flag in the signal handler > and then handle that in a main loop of the program. Doing advanced > stuff in a signal handler is usually dangerous non-compatible > territory. > > > > -- > J. -- ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------