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
+16.3k Golang : File path independent of Operating System
+9.2k Golang : Extract or copy items from map based on value
+6.4k Golang : Warp text string by number of characters or runes example
+10.6k Golang : Natural string sorting example
+3.8k Detect if Google Analytics and Developer Media are loaded properly or not
+5k JavaScript/JQuery : Redirect page examples
+27.1k PHP : Convert(cast) string to bigInt
+10.7k Golang : Create Temporary File
+7.5k Golang : Lock executable to a specific machine with unique hash of the machine
+6k Golang : How to get capacity of a slice or array?
+27.3k PHP : Count number of JSON items/objects
+4.5k Chrome : How to block socketloop.com links in Google SERP?