
上QQ阅读APP看书,第一时间看更新
How to do it…
- Open the console and create the folder chapter01/recipe06.
- Navigate to the directory.
- Create the main.go file with the following content:
package main
import (
"fmt"
"os"
"os/exec"
"strconv"
)
func main() {
pid := os.Getpid()
fmt.Printf("Process PID: %d \n", pid)
prc := exec.Command("ps", "-p", strconv.Itoa(pid), "-v")
out, err := prc.Output()
if err != nil {
panic(err)
}
fmt.Println(string(out))
}
- Run the code by executing the go run main.go.
- See the output in the Terminal:
