【发布时间】:2019-06-12 22:19:10
【问题描述】:
我想使用 Golang for Linux os 从特定子进程 id (pid) 获取父进程 id (ppid)
我有这段代码,它给出了当前进程的 ppid 和 pid,但我想检索我指定的子进程的 ppid,而不是当前进程。
package main
import (
"fmt"
"os"
)
func main() {
pid := os.Getpid()
parentpid := os.Getppid()
fmt.Printf("The parent process id of %v is %v\n", pid, parentpid)
}
有没有办法像 os.Getppid(pid) 这样传递 pid 或任何其他方法来检索 Golang 中指定 pid 的 ppid?
【问题讨论】:
-
这里没有标准库 Go 函数。 linux上的所有进程信息都存储在
/proc中,更多详情见man proc