[GHC] #3081: Double output after Ctrl+C on Windows

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Mar 16 20:07:31 EDT 2009


On Mon, 2009-03-16 at 16:36 +0000, Neil Mitchell wrote:
> >> system "cp foo foo.bup" >> deleteFile "foo"
> >>
> >> If I Ctrl+C during the cp did I just delete my one copy of foo?
> >
> > On Windows, Ctrl-C will unblock a blocked system call.  e.g. read() returns
> > with zero.  Apparently system "foo" also returns as soon as you press
> > Ctrl-C, I'm not entirely sure why.  Perhaps because the program has been
> > killed?
> 
> So, to check my understanding:
> 
> * Haskell program invokes system
> * Use presses Ctrl+C
> * System returns and Haskell program continues executing
> * Ctrl+C is thrown and Haskell program aborts
> 
> That sounds really dangerous - like a race condition between the
> system returning and the Haskell program aborting.

I've no idea how Ctrl-C works on Windows but since it may be relevant
and possibly useful let me just walk through how it should(*) work on
Unix with the new process library implementation that we've been
discussing. (I think it also works fine with the current process
implementation on Unix)

For system() we "delegate" Ctrl-C handling to the child process. That
means that while the child process is running we take no action when we
(the parent process) receive the signal corresponding to Ctrl-C. No
exception is raised, we do not attempt to kill the child process,
nothing. When the child process terminates we check how it terminated.
If it terminated due to the Ctrl-C signal then we raise a synchronous
Haskell exception. If it terminated with a normal exit code then no
exception is raised (we deem the child process to have handled the
Ctrl-C, think of programs like ghci which handle Ctrl-C).

Duncan

(*) "should". The implementation does not do this yet.



More information about the Glasgow-haskell-bugs mailing list