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
+5.5k Golang : Struct field tags and what is their purpose?
+11.4k Golang : How to detect a server/machine network interface capabilities?
+7.5k Setting $GOPATH environment variable for Unix/Linux and Windows
+11.1k Golang : Generate DSA private, public key and PEM files example
+10k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+13.1k Golang : Get constant name from value
+9.8k Golang : Compare files modify date example
+16.3k Golang : Gzip file example
+18.3k Golang : Generate thumbnails from images
+12.1k Elastic Search : Return all records (higher than default 10)
+8.1k Golang : Generate Datamatrix barcode
+9.4k Golang : interface - when and where to use examples