O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

  1. Open the console and create the folder chapter01/recipe07.
  2. Navigate to the directory.
  3. Create the main.go file with the following content:
        package main        import (          "fmt"          "os"          "os/signal"          "syscall"        )        func main() {          // Create the channel where the received          // signal would be sent. The Notify          // will not block when the signal          // is sent and the channel is not ready.          // So it is better to          // create buffered channel.          sChan := make(chan os.Signal, 1)          // Notify will catch the          // given signals and send          // the os.Signal value          // through the sChan.          // If no signal specified in           // argument, all signals are matched.          signal.Notify(sChan,            syscall.SIGHUP,            syscall.SIGINT,            syscall.SIGTERM,            syscall.SIGQUIT)          // Create channel to wait till the

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required