File: example.go

package info (click to toggle)
golang-github-erikdubbelboer-gspt 0.0~git20161002.0.6ce3e9d-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 88 kB
  • ctags: 34
  • sloc: ansic: 167; makefile: 3
file content (52 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (2)
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
52

package main

import (
  "fmt"
  "strings"
  "time"

  "os"
  "os/exec"

  "github.com/ErikDubbelboer/gspt"
)

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

  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)
}