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
+5.5k Javascript : Put image into Chrome browser's console
+9.4k Golang : Post data with url.Values{}
+21.8k Golang : Get executable name behind process ID example
+3.2k Golang : Calculate a pip value and distance to target profit example
+16.4k Android Studio : AlertDialog and EditText to get user string input example
+11.9k Golang : Accurate and reliable decimal calculations
+4.5k Golang : Handling image beyond OpenCV video capture boundary
+14.3k Golang : Gzip file example
+27.1k Get client IP Address in Go
+7.7k Golang : interface - when and where to use examples
+26.2k Golang : bufio.NewReader.ReadLine to read file line by line
+10.7k Golang : Reverse IP address for reverse DNS lookup example