Home »
Golang »
Golang Reference
Golang os.Getpid() Function with Examples
Golang | os.Getpid() Function: Here, we are going to learn about the Getpid() function of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 19, 2021
os.Getpid()
In the Go language, the os package provides a platform-independent interface to operating system (Unix-like) functionality. The Getpid() function is an inbuilt function of the os package, it is used to get the process id of the caller.
It accepts nothing and returns an integer that is the process id of the caller.
Syntax
func Getpid() int
Parameters
Return Value
The return type of the os.Getpid() function is an int, it returns the process id of the caller.
Example
// Golang program to demonstrate the
// example of Getpid() function
package main
import (
"fmt"
"os"
)
func main() {
pid := os.Getpid()
fmt.Printf("pid: %T, %v\n",
pid, pid)
}
Output:
pid: int, 11
Golang os Package »