Endangered I/O operations
Thu, 24 May 2001 10:10:15 +0100
> A related wish I have is that a Haskell program receiving a HUP signal
> should flush its buffers before terminating.
> Or even better, flush on some other signal that does not terminate
> the program.
Well, you can catch HUP in the program and initiate a flush. Actually
just doing System.exitWith will cause all the open handles to be flushed
and closed, but note that if you do System.exitWith from a signal
handler it won't terminate the program any more... ;-)
I think we've just found an argument in favour of having System.exitWith
always terminate the program even from a child thread.
If you want to *just* flush all the open handles from a signal handler,
you'll need to keep track of the open handles and flush them by hand
from the signal handler. See the Posix library documentation for
details on setting up a signal handler.