Skip to content

Commit deb7f17

Browse files
committed
bumped to v0.1.2
1 parent 8b47206 commit deb7f17

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

l0la.go

+22-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99
)
1010

11-
const Version = "v0.1.1"
11+
const Version = "v0.1.2"
1212

1313
func Watch(pid int) {
1414
lines := make([]io.Writer, 0)
@@ -25,22 +25,27 @@ func Watch(pid int) {
2525
pad := 26
2626
s := NewSpinnerAnim()
2727

28-
for {
29-
fmt.Fprint(lines[0], Logo()+"\n")
30-
fmt.Fprintf(lines[0], "%s watching pid: %v %s \n", s.Next(), pid, Pidgrepstatus(pid))
31-
fmt.Fprintf(lines[0], "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n")
32-
fmt.Fprintf(lines[0], "┃ TCP conns ┃ %s ┃\n", Red(LPad(pad, FGroup(Conngrep(pid)))))
33-
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
34-
fmt.Fprintf(lines[0], "┃ Open files ┃ %s ┃\n", Yellow(LPad(pad, FGroup(Filegrep(pid)))))
35-
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
36-
fmt.Fprintf(lines[0], "┃ Threads ┃ %s ┃\n", Blue(LPad(pad, FGroup(Threadgrep(pid)))))
37-
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
38-
fmt.Fprintf(lines[0], "┃ RSS bytes ┃ %s ┃\n", Gray(8, LPad(pad, FGroup(Memgrep(pid)))))
39-
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
40-
fmt.Fprintf(lines[0], "┃ CPU percent ┃ %s ┃\n", Magenta(LPad(pad, Cpugrep(pid))))
41-
fmt.Fprintf(lines[0], "┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n")
42-
l0.Flush()
43-
time.Sleep(time.Millisecond * 500)
28+
if PidgrepActive(pid) {
29+
for {
30+
fmt.Fprint(lines[0], Logo()+"\n")
31+
fmt.Fprintf(lines[0], "%s watching pid: %v %s \n", s.Next(), pid, Pidgrepstatus(pid))
32+
fmt.Fprintf(lines[0], "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n")
33+
fmt.Fprintf(lines[0], "┃ TCP conns ┃ %s ┃\n", Red(LPad(pad, FGroup(Conngrep(pid)))))
34+
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
35+
fmt.Fprintf(lines[0], "┃ Open files ┃ %s ┃\n", Yellow(LPad(pad, FGroup(Filegrep(pid)))))
36+
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
37+
fmt.Fprintf(lines[0], "┃ Threads ┃ %s ┃\n", Blue(LPad(pad, FGroup(Threadgrep(pid)))))
38+
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
39+
fmt.Fprintf(lines[0], "┃ RSS bytes ┃ %s ┃\n", Gray(8, LPad(pad, FGroup(Memgrep(pid)))))
40+
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
41+
fmt.Fprintf(lines[0], "┃ CPU percent ┃ %s ┃\n", Magenta(LPad(pad, Cpugrep(pid))))
42+
fmt.Fprintf(lines[0], "┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n")
43+
l0.Flush()
44+
time.Sleep(time.Millisecond * 500)
45+
}
46+
} else {
47+
fmt.Printf(Logo())
48+
fmt.Printf("\n%d not a pid, insufficient privileges or dead?\n", pid)
4449
}
4550
}
4651

pidgrep.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88

99
const pidgrepcmd = "ps -p %d | grep -v PID | wc -l"
1010

11-
func Pidgrep(pid int) bool {
11+
func PidgrepActive(pid int) bool {
1212
cmd := fmt.Sprintf(pidgrepcmd, pid)
1313
stdout, _, _ := Shellout(cmd)
1414
r, _ := strconv.Atoi(strings.TrimSpace(stdout))
1515
return r == 1
1616
}
1717

1818
func Pidgrepstatus(pid int) string {
19-
if Pidgrep(pid) {
19+
if PidgrepActive(pid) {
2020
return "[ACTIVE]"
2121
} else {
2222
return "[DEAD?]"

0 commit comments

Comments
 (0)