Golang : Get own process identifier
There are times when developer needs to know the own process identifier(PID) of the executing program during runtime. This is to facilitate task such as scheduling graceful shutdown of the process or for other reasons.
This short code example utilized the os.Getpid()
function to retrieve own process identifier.
package main
import (
"fmt"
"os"
"strconv"
)
func main() {
pid := os.Getpid()
fmt.Println("Own process identifier: ", strconv.Itoa(pid))
}
See also : Golang : How to get own program name during runtime ?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+29.4k Golang : Save map/struct to JSON or XML file
+8.3k Golang : Metaprogramming example of wrapping a function
+16.9k Golang : read gzipped http response
+7.2k Golang : Null and nil value
+18.8k Unmarshal/Load CSV record into struct in Go
+6.9k Golang : Muxing with Martini example
+6.2k Golang : Create new color from command line parameters
+6.3k Golang : Calculate US Dollar Index (DXY)
+18.5k Golang : Logging with logrus
+6.4k Golang : Detect face in uploaded photo like GPlus
+8.1k Golang : Get all countries phone codes