How to get the running process' pid in Go?

How to get the running process' pid in Go lang?

asked Jun 5 by dtivl (2,500 points)

1 Answer

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: %d\n", os.Getpid())
pid: 6756
10
<nil>
gore> 
answered Jun 5 by dtivl (2,500 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...