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.3k Golang : Dealing with postal or zip code example
+8.9k Golang : Print how to use flag for your application example
+2.2k Golang : Switch Redis database redis.NewClient
+15.9k Golang : Get future or past hours, minutes or seconds
+9.5k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+14.3k Golang : How to convert(cast) IP address to string?
+8.3k Golang : Qt Yes No and Quit message box example
+7.2k How to show different content from website server when AdBlock is detected?
+23.4k Golang : convert rune to integer value
+18.9k Nginx + FastCGI + Go Setup.
+5k Golang : Extract unicode string from another unicode string example
+24.4k Golang : How to write CSV data to file