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.2k Responsive Google Adsense
+29.8k Golang : How to get HTTP request header information?
+9.3k Golang : How to get username from email address
+16.3k Golang : Find out mime type from bytes in buffer
+14.7k Golang : Get URI segments by number and assign as variable example
+9.6k Golang : Copy map(hash table) example
+5.9k Golang : Generate multiplication table from an integer example
+32.3k Golang : Math pow(the power of x^y) example
+9.8k Golang : Function wrapper that takes arguments and return result example
+9.7k Golang : interface - when and where to use examples
+9k Golang : How to capture return values from goroutines?
+13.5k Golang : Query string with space symbol %20 in between