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
+12.6k Golang : Fix image: unknown format error
+5.2k Golang : Create new color from command line parameters
+7.7k Golang : Accept any number of function arguments with three dots(...)
+7.8k Golang : Heap sort example
+31.2k Golang : Regular Expression for alphanumeric and underscore
+6.3k Golang : Check to see if *File is a file or directory
+3.7k Chrome : How to block socketloop.com links in Google SERP?
+14.2k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+5.8k How to let Facebook Login button redirect to a particular URL ?
+6.5k Golang : Detect sample rate, channels or latency with PortAudio
+4.5k Golang : Stop goroutine without channel
+12.1k Facebook PHP getUser() returns 0