How to get process id in Golang?

Golang | Learn how to get the process id using the Getpid() function?
Submitted by IncludeHelp, on November 07, 2021

Process id stands for Process Identifier, it is a unique number to identify the process. Each process has its unique identifier – to uniquely identify an active process.

In the Go programming language, there is a package called os that provides a platform-independent interface to operating system functionality. It has a function named Getpid() that returns the process id of the caller i.e., the process id of the current running process.

Syntax:

func Getpid() int

The function is called without the parameter and returns the process id.

Example:

// Golang program to get the process id
// of the current running process

package main

import (
	"fmt"
	"os"
)

func main() {
	process_id := os.Getpid()
	fmt.Println("Process Id is", process_id)
}

Output:

Process Id is 11

Golang FAQ »



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.