ADVERTISEMENT
ADVERTISEMENT

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!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.