1

The following golang code catches CTRL+C when run from a DOS prompt, but when I run it from Cygwin it doesn't catch anything when CTRL+C is pressed.

What does Cygwin do when CTRL+C is pressed? My OS is Win7 64 bit running 32 bit Cygwin.

    func main() {
        c := make(chan os.Signal, 1)
        signal.Notify(c, os.Interrupt)
        go func(){
        for sig := range c {
            fmt.Println(sig.String())
        }
        }()

        time.Sleep(5000 * time.Millisecond) 
        fmt.Println("Done")
    }
5
  • In msys whether or not I get output on programs that catch interrupts depend on whether I use go run or go build followed by whatever.exe. Not sure if Cygwin has the same weirdness.
    – Linear
    Commented Apr 28, 2014 at 20:53
  • After typing ctrl c terminal cygwin into Google I'll guess your cygwin is < 1.7.18.
    – Volker
    Commented Apr 28, 2014 at 22:32
  • @Volker I Googled as well, that seems to be "ctrl+c doesn't work at all". There's a glut of completely separate questions about having trouble capturing signal interrupts from Windows programs run under Cygwin, which I haven't found a satisfactory response to yet (something about pseudoterminals or somesuch). What I'm getting is that it's possible that Cygwin sends a literal Unix SIGINT rather than whatever interrupt code Windows uses, but I'm not sure.
    – Linear
    Commented Apr 28, 2014 at 23:41
  • @Volker - I have 1.7.24 Commented Apr 30, 2014 at 1:43
  • @Jsor - My code doesn't catch signals from Cygwin in either case. When I do go run ... Ctrl+c kills the go run process but the go program runs to completion. When I do ./signal.catcher.exe the Ctrl+c kills the program (doesn't run to completion). The signals are not caught in either case. Commented Apr 30, 2014 at 2:00

1 Answer 1

5

The answer I got on the cygwin mail list is that in order for signaling to work the program has to be compiled and linked with a Cygwin compiler and linker. Cygwin is not a supported platform for golang, so I'm not going to be able to catch CTRL+C in a golang program launched from Cygwin.

Not the answer you're looking for? Browse other questions tagged or ask your own question.