File: example.go

package info (click to toggle)
golang-github-erikdubbelboer-gspt 0.0~git20210805.ce36a51-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 96 kB
  • sloc: ansic: 203; makefile: 3
file content (51 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main

import (
	"fmt"
	"strings"
	"time"

	"os"
	"os/exec"

	"github.com/erikdubbelboer/gspt"
)

func main() {
	fmt.Println("HaveSetProcTitle:", gspt.HaveSetProcTitle)
	fmt.Println("HaveSetProcTitleFast:", gspt.HaveSetProcTitleFast)

	gspt.SetProcTitle("some title")

	fmt.Println("The title has been set, 'ps a' now shows:")

	out, err := exec.Command("ps", "aux").Output()
	if err != nil {
		// Could not execute 'ps'.
		return
	}
	lines := strings.Split(string(out), "\n")
	fmt.Println(lines[0])
	for _, line := range lines {
		if strings.Contains(line, "some title") {
			fmt.Println(line)
		}
	}

	fmt.Println("----")
	fmt.Println("os.Environ() should still contain things like:")
	fmt.Println("PATH =", os.Getenv("PATH"))

	fmt.Println("----")
	fmt.Println("os.Args should still be correct:")

	for i, a := range os.Args {
		fmt.Println(i, ":", a)
	}

	fmt.Println("----")
	fmt.Println("You can now check the output of 'ps a' or 'top'.")
	fmt.Println("Press Ctrl+C to kill this program.")

	time.Sleep(time.Minute * 5)
}