What is the golang equivalent of the ANSI C raise() function?
See here for an example usage of raise():
What is the golang equivalent of the ANSI C raise() function?
See here for an example usage of raise():
You can do it using the os package:
p, err := os.FindProcess(os.Getpid())
p.Signal(os.Interrupt)
Additionally, you can catch signals sent to your process using the os/signal package, which allows you to specify a channel on which to receive signals:
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
sig := <-c
fmt.Printf("Got %s!
", sig.String())
This implementation won't work on the go playground because it won't let you import os/signal, but if you run the code locally, it should work fine (does on my machine): http://play.golang.org/p/QcrRl2BeNS