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.7k Golang : Combine slices of complex numbers and operation example
+7.6k Linux : How to fix Brother HL-1110 printing blank page problem
+13.9k Golang : Get user input until a command or receive a word to stop
+17.3k Golang : Capture stdout of a child process and act according to the result
+18.8k Golang : Find IP address from string
+5.4k Golang : Print instead of building pyramids
+8k Golang : Example of how to detect which type of script a word belongs to
+8.6k Your page has meta tags in the body instead of the head
+35.4k Golang : Upload and download file to/from AWS S3
+9.8k PHP : Get coordinates latitude/longitude from string
+5.9k Fix yum-complete-transaction error
+15.5k Golang : Get query string value on a POST request