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
+30k Golang : How to get HTTP request header information?
+24.7k Golang : Time slice or date sort and reverse sort example
+11.6k Golang : Handle API query by curl with Gorilla Queries example
+20.9k Android Studio : AlertDialog and EditText to get user string input example
+11.8k Android Studio : Create custom icons for your application example
+6.2k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+19.7k Golang : Close channel after ticker stopped example
+9.6k Golang : Get all countries currencies code in JSON format
+25.4k Golang : Get current file path of a file or executable
+6.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+5.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag