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
+32.4k Golang : All update packages with go get command
+9.7k Golang : Command line file upload program to server example
+7.8k Golang : Find network service name from given port and protocol
+4k Golang : Customize scanner.Scanner to treat dash as part of identifier
+4.3k Javascript : Change page title to get viewer attention
+5.3k Javascript : Generate random key with specific length
+3.6k Java : Generate multiplication table example
+4.2k Golang : Constant and variable names in native language
+12.5k Golang : How to get year, month and day?
+4.8k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+5.2k PageSpeed : Clear or flush cache on web server
+23.8k Golang : Convert long hexadecimal with strconv.ParseUint example