35 lines
693 B
Go
35 lines
693 B
Go
package main
|
|
|
|
/*
|
|
#include <windows.h>
|
|
BOOL SetPriority(DWORD pid, int priority) {
|
|
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
|
|
if (!h) return FALSE;
|
|
BOOL success = SetPriorityClass(h, priority);
|
|
CloseHandle(h);
|
|
return success;
|
|
}
|
|
*/
|
|
import "C"
|
|
import (
|
|
"github.com/shirou/gopsutil/process"
|
|
"os"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
C.SetPriority(C.DWORD(os.Getpid()), 0x00000040)
|
|
for {
|
|
processes, _ := process.Processes()
|
|
for _, proc := range processes {
|
|
memoryInfo, err := proc.MemoryInfo()
|
|
if err == nil && memoryInfo.RSS >= (0.5*1024*1024*1024) {
|
|
C.SetPriority(C.DWORD(proc.Pid), 0x00000080)
|
|
}
|
|
}
|
|
runtime.GC()
|
|
time.Sleep(time.Minute)
|
|
}
|
|
}
|