-
Notifications
You must be signed in to change notification settings - Fork 0
SignalHandling
Dave Day edited this page Dec 10, 2014
·
2 revisions
Sometimes an application needs to save internal state or perform some cleanup activity before it exits, or needs to be able to reload a configuration file or write a memory/cpu profile on demand. In UNIX-like operating systems, signals can accomplish these tasks.
The following code demonstrates a program that waits for an interrupt signal and removes a temporary file when it occurs.
package main
import (
"io/ioutil"
"os"
"os/signal"
)
func main() {
f, err := ioutil.TempFile("", "test")
if err != nil {
panic(err)
}
defer os.Remove(f.Name())
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
<-sig
}
- Home
- Getting started with Go
- Working with Go
- Learning more about Go
- The Go Community
- Using the Go toolchain
- Additional Go Programming Wikis
- Online Services that work with Go
- Troubleshooting Go Programs in Production
- Contributing to the Go Project
- Platform Specific Information
- Release Specific Information