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
+16k Golang : Execute terminal command to remote machine example
+4.6k Linux : How to set root password in Linux Mint
+6.8k Golang : Get environment variable
+11.6k Golang : Get remaining text such as id or filename after last segment in URL path
+20.2k Golang : Saving private and public key to files
+14.6k JavaScript/JQuery : Detect or intercept enter key pressed example
+15.2k Golang : Get current time from the Internet time server(ntp) example
+13.7k Golang : Check if a file exist or not
+19.4k Golang : How to get time from unix nano example
+8.9k Golang : How to get ECDSA curve and parameters data?
+13.5k Golang : convert rune to unicode hexadecimal value and back to rune character
+5k PHP : Hide PHP version information from curl