How to get the running process’ pid in Go?

Posted on In QA

How 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> 

Leave a Reply

Your email address will not be published. Required fields are marked *