×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

How to get the parent process identification using syscall in Golang?

Here, we will learn to get the parent process identification using syscall in Golang.
Submitted by IncludeHelp, on November 13, 2021 [Last updated : March 05, 2023]

Getting the parent process identification using syscall in Golang

In the Go programming language, to get the parent process identification using syscall – we use the Getppid() function of the syscall package. The Getppid() function returns the process ID of the parent of the calling process.

Syntax

func Getpid() (pid int)

Consider the below example demonstrating how to get the parent process identification using syscall in Golang?

Golang code to get the parent process identification using syscall

package main

import (
	"fmt"
	"syscall"
)

func main() {
	// Using the Getpid(),
	// Getting the parent process ID
	pid := syscall.Getgid()

	// Printing the parent process ID
	fmt.Println("parent process ID:", pid)
}

Output

parent process ID: 14022

Golang syscall Package Programs »





Comments and Discussions!

Load comments ↻





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