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
+10k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+5k Python : Find out the variable type and determine the type with simple test
+6.6k Golang : Combine slices of complex numbers and operation example
+22.8k Golang : untar or extract tar ball archive example
+10.5k Swift : Convert (cast) String to Integer
+14.9k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+30.6k Golang : Remove characters from string example
+7.9k Golang : Lock executable to a specific machine with unique hash of the machine
+36k Golang : Integer is between a range
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+18.7k Golang : Iterating Elements Over A List
+6k Linux/MacOSX : Search for files by filename and extension with find command