8
8
"time"
9
9
)
10
10
11
- const Version = "v0.1.1 "
11
+ const Version = "v0.1.2 "
12
12
13
13
func Watch (pid int ) {
14
14
lines := make ([]io.Writer , 0 )
@@ -25,22 +25,27 @@ func Watch(pid int) {
25
25
pad := 26
26
26
s := NewSpinnerAnim ()
27
27
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 )
44
49
}
45
50
}
46
51
0 commit comments