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
+6k Android Studio : Rating bar example
+8.2k Golang : Characters limiter example
+15.1k Golang : Find smallest number in array
+4.9k Golang : Mapping Iban to Dunging alphabets
+17.6k Golang : How to Set or Add Header http.ResponseWriter?
+12.2k Golang : Find commonalities in two slices or arrays example
+5.4k Golang : Getting Echo framework StartAutoTLS to work
+25.5k Golang : Detect (OS) Operating System
+13.3k Golang : Read integer from file into array
+5.9k Golang : How to execute code at certain day, hour and minute?
+3.8k Golang : Intercept, inject and replay HTTP traffics from web server