Remove unneeded loop and reduce cpu usage
This commit is contained in:
20
main.go
20
main.go
@@ -101,7 +101,6 @@ func reniced(cnf Config) {
|
||||
for _, p := range processList {
|
||||
ok := pool.TrySubmit(func() {
|
||||
if processName, err := p.Name(); err == nil {
|
||||
for _, k := range cnf.Kill {
|
||||
if killSignal := kill[processName]; killSignal != "" {
|
||||
switch killSignal {
|
||||
case "kill":
|
||||
@@ -111,7 +110,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
case "stop":
|
||||
@@ -122,7 +121,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
} else if err == nil && s[0] == "stop" && cnf.Debug {
|
||||
@@ -138,7 +137,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
case "int":
|
||||
@@ -148,7 +147,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
case "quit":
|
||||
@@ -158,7 +157,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
case "abrt":
|
||||
@@ -168,7 +167,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
case "hup":
|
||||
@@ -178,7 +177,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
case "usr1":
|
||||
@@ -188,7 +187,7 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
case "usr2":
|
||||
@@ -198,12 +197,11 @@ func reniced(cnf Config) {
|
||||
log.Printf(
|
||||
"Matching processName with killProcessname (%s), SIG%s sent",
|
||||
processName,
|
||||
strings.ToUpper(k.Sig),
|
||||
strings.ToUpper(killSignal),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Для каждого процесса извлекаем его текущий priority.
|
||||
if currentPrioLevel, err := syscall.Getpriority(syscall.PRIO_PROCESS, int(p.Pid)); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user