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/recipe09.
  2. Navigate to the directory.
  3. Create the main_running.go file with the following content:
        package main        import (          "fmt"          "os/exec"          "runtime"        )        func main() {          var cmd string          if runtime.GOOS == "windows" {            cmd = "timeout"          } else {            cmd = "sleep"          }          proc := exec.Command(cmd, "1")          proc.Start()          // No process state is returned          // till the process finish.          fmt.Printf("Process state for running process: %v\n",                     proc.ProcessState)          // The PID could be obtain          // event for the running process          fmt.Printf("PID of running process: %d\n\n",                      proc.Process.Pid)        }
  1. Run the code by executing go run main_running.go.
  2. See the output in the Terminal:
  1. Create the main.go file with the following content: ...

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