×

Go Tutorial

Go Basics

Go Variables

Go Literals

Go Type Handling

Go Operators

Go Decision Making

Go Loops

Go Functions

Go String

Go Arrays

Go Slices

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

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 »

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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