Golang os.Getpid(), FindProcess() and Getppid() functions example
package os
Golang os.Getpid(), FindProcess() and Getppid() functions usage example. Useful in situation where you want to trace a child processes of a parent process within your Golang program.
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)
proc, err := os.FindProcess(pid) // or replace with other process number
if err != nil {
panic(err)
}
fmt.Println(proc.Pid)
}
References :
http://golang.org/pkg/os/#Getpid
Advertisement
Something interesting
Tutorials
+10k Golang : Get escape characters \u form from unicode characters
+7.9k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+6.8k Swift : substringWithRange() function example
+6.9k Golang : How to solve "too many .rsrc sections" error?
+5.5k Golang : Stop goroutine without channel
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+18.6k Golang : Generate thumbnails from images
+11.1k Golang : Read until certain character to break for loop
+35.9k Golang : Integer is between a range
+36k Golang : Get file last modified date and time
+13.4k Golang : Generate Code128 barcode
+8.5k Linux/Unix : fatal: the Postfix mail system is already running