How to get the running process’ pid in Go?
Posted on In QAHow to get the running process’ pid in Go lang?
In Go, you may call the os.Getpid()
func from the os
package to get the parent process’ pid.
func Getpid() int
Getppid returns the process id of the caller.
One example is as follows.
$ gore
gore version 0.2.6 :help for help
gore> :import "fmt"
gore> :import "os"
gore> fmt.Printf("pid: %dn", os.Getpid())
pid: 6756
10
<nil>
gore>