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
+6.3k PHP : Proper way to get UTF-8 character or string length
+10.1k Golang : How to profile or log time spend on execution?
+16.3k CodeIgniter/PHP : Create directory if does not exist example
+14.4k Golang : How to check if your program is running in a terminal
+13.2k Golang : Linear algebra and matrix calculation example
+14.5k Golang : Reset buffer example
+9.8k Golang : Turn string or text file into slice example
+12.2k Golang : Print UTF-8 fonts on image example
+12.4k Golang : flag provided but not defined error
+3.6k Golang : Switch Redis database redis.NewClient
+9.1k Golang : does not implement flag.Value (missing Set method)