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
+3.7k Mac OSX : Get disk partitions' size, type and name
+12.7k Golang : How to convert a number to words
+14.9k Golang : convert string or integer to big.Int type
+9.5k Golang : Create matrix with Gonum Matrix package example
+8k Golang : Go as a script or running go with shebang/hashbang style
+6.1k Web : How to see your website from different countries?
+8.6k Golang : Resumable upload to Google Drive(RESTful) example
+15.8k Golang : Get number of CPU cores
+37.8k Golang : Remove dashes(or any character) from string
+12.1k Golang : Generate Code128 barcode
+26.8k Golang : Connect to database (MySQL/MariaDB) server
+16.2k Golang : Linked list example