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
+14.4k Golang : Overwrite previous output with count down timer
+6.8k Golang : How to solve "too many .rsrc sections" error?
+10.7k PHP : Convert(cast) bigInt to string
+22k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+13k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+21.6k Golang : Convert string slice to struct and access with reflect example
+28.3k Golang : Change a file last modified date and time
+12.9k Golang : Calculate elapsed years or months since a date
+15.6k Golang : How to login and logout with JWT example
+38.9k Golang : How to iterate over a []string(array)
+22.2k Golang : Read directory content with filepath.Walk()
+4.6k Facebook : How to place save to Facebook button on your website