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
+6.5k Golang : File system scanning
+23.3k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+8.8k Golang : Validate IPv6 example
+4.8k Golang : Frobnicate or tweaking a string example
+10.3k Android Studio : Create custom icons for your application example
+13k Golang : Get current time
+32.8k Golang : Create x509 certificate, private and public keys
+2.8k Java : Get FX sentiment from website example
+21.5k Golang : How to read JPG(JPEG), GIF and PNG files ?
+7.6k Golang : How to check if input string is a word?
+6k Golang : Muxing with Martini example
+20.9k Golang : Join arrays or slices example