-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (34 loc) · 857 Bytes
/
main.go
File metadata and controls
42 lines (34 loc) · 857 Bytes
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
package main
import (
"flag"
"log"
"os"
"time"
)
var (
fsys = flag.String("s", "usr1", "kill syscall sent")
fper = flag.Float64("p", 90, "percentage threshold before sending a kill signal")
fdur = flag.Duration("i", time.Duration(time.Minute), "interval of each check")
fver = flag.Bool("v", false, "verbose")
selfPID int = os.Getpid()
)
func main() {
flag.Parse()
if flag.NArg() == 0 {
log.Fatal("Arguments needed")
}
if sysc[*fsys] == 0 {
log.Fatal("Signal not recognised")
}
log.Printf("Looking for commands containing: %q\n", flag.Args())
log.Printf("Interval fixed to: %v\n", *fdur)
log.Printf("Looking for %%CPU usage higher than %v%%\n", *fper)
log.Printf("Kill signal to send: %q\n\n", sysc[*fsys])
var pd, npd []uint64
for {
pd = checkProcs(flag.Args()...)
killProcs(pd, npd)
time.Sleep(*fdur)
npd = pd
}
}