Question

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")
    }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top