July 2019
Intermediate to advanced
458 pages
12h 12m
English
The first two things that a program may want to know are its identifier and the parent identifier, that is, PID and PPID. This is actually pretty straightforward – the os.Getpid() and os.Getppid() functions both return an integer value with both of the identifiers, as shown in the following code:
package mainimport ( "fmt" "os")func main() { fmt.Println("Current PID:", os.Getpid()) fmt.Println("Current Parent PID:", os.Getppid())}
The full example is available at https://play.golang.org/p/ng0m9y4LcD5.
Read now
Unlock full access