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 Unix/Linux : How to archive and compress entire directory ?
+10.6k Golang : Generate random elements without repetition or duplicate
+14.8k nginx: [emerg] unknown directive "ssl"
+21.2k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+10.2k Golang : Bubble sort example
+14.2k Golang : Execute function at intervals or after some delay
+14.7k Golang : How do I get the local IP (non-loopback) address ?
+28.6k Golang : Get first few and last few characters from string
+5.4k Fix yum-complete-transaction error
+22.4k Golang : Calculate time different
+6.9k Golang : Dealing with postal or zip code example