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
+20.9k Android Studio : AlertDialog and EditText to get user string input example
+9.7k Golang : How to extract video or image files from html source code
+8.2k Golang : Get all countries phone codes
+9.8k Golang : Eroding and dilating image with OpenCV example
+10.5k Golang : How to check if a website is served via HTTPS
+7.8k Golang : Command line ticker to show work in progress
+21.3k Golang : Get password from console input without echo or masked
+5.4k JavaScript/JQuery : Redirect page examples
+33.2k Golang : How to check if a date is within certain range?
+7.8k Golang : get the current working directory of a running program
+17.1k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+24.1k Golang : Call function from another package