Skip to content

d10v/pstree

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pstree

GoDoc

pstree is a simple minded package to retrieve the process tree from a given PID.

Installation

sh> go get github.com/sbinet/pstree

Documentation

Documentation is available on godoc:

https://godoc.org/github.com/sbinet/pstree

Example

package main

import (
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"

	"github.com/sbinet/pstree"
)

func main() {
	pid, err := strconv.Atoi(os.Args[1])
	if err != nil {
		log.Fatalf("could not retrieve pid: %v\n", err)
	}
	tree, err := pstree.New()
	if err != nil {
		log.Fatalf("error: %v\n", err)
	}

	fmt.Printf("tree[%d]: %v\n", pid, tree.Procs[pid])
	display(pid, tree, 1)
}

func display(pid int, tree *pstree.Tree, indent int) {
	str := strings.Repeat("  ", indent)
	for _, cid := range tree.Procs[pid].Children {
		proc := tree.Procs[cid]
		fmt.Printf("%s%#v\n", str, proc)
		display(cid, tree, indent+1)
	}
}

About

a simple API to retrieve a process tree

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%