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.8k Golang : Saving private and public key to files
+6.3k Golang : Extract XML attribute data with attr field tag example
+7.1k Golang : How to setup a disk space used monitoring service with Telegram bot
+22.9k Golang : untar or extract tar ball archive example
+9.5k Golang : How to protect your source code from client, hosting company or hacker?
+14.1k Golang : concatenate(combine) strings
+5.8k Golang : Error handling methods
+18.1k Golang : Login and logout a user after password verification and redirect example
+12k Golang : Convert decimal number(integer) to IPv4 address
+7.9k Golang : Lock executable to a specific machine with unique hash of the machine
+10.8k Golang : Resolve domain name to IP4 and IP6 addresses.
+21.3k Golang : Get password from console input without echo or masked