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 Golang : Calculate how many weeks left to go in a given year
+3.9k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+4.8k nginx : force all pages to be SSL
+26k Golang : Record voice(audio) from microphone to .WAV file
+8k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+21.6k Golang : Calculate time different
+18.2k Golang : Compare floating-point numbers
+7k Golang : Qt splash screen with delay example
+5.2k Golang : Detect face in uploaded photo like GPlus
+16.1k Golang : When to use init() function?
+16.6k Golang : Get all upper case or lower case characters from string example
+5.7k Golang : Find the shortest line of text example