To build: go build -o int_test.exe main.go
.
To run: int_test.exe
.
package main | |
import "os/signal" | |
import "os" | |
import "fmt" | |
import "time" | |
func main() { | |
// Prints "Still alive..." every second | |
ticker := time.NewTicker(time.Second) | |
go func() { | |
for range ticker.C { | |
fmt.Println("Still alive...") | |
} | |
}() | |
// Prints "Died." when program exits. | |
defer fmt.Println("Died.") | |
// Prints "Received signal: " when a signal is received. | |
c := make(chan os.Signal) | |
signal.Notify(c) | |
select { | |
case s := <-c: | |
fmt.Printf("Received signal: %v\n", s) | |
} | |
} |