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
+5k Golang : Extract unicode string from another unicode string example
+7k Golang : Append and add item in slice
+8.2k Golang : Create unique title slugs example
+5.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+9.9k Golang : Intercept and process UNIX signals example
+11k Golang : How to parse plain email text and process email header?
+6.4k Golang : Example of how to detect which type of script a word belongs to
+3.8k Golang : How to pass data between controllers with JSON Web Token
+12k Golang : Get user input until a command or receive a word to stop
+6.8k Golang : Get today's weekday name and calculate target day distance example
+18.3k Golang : Archive directory with tar and gzip
+19.9k Golang : Get password from console input without echo or masked