1

initial commit

This commit is contained in:
2023-01-15 03:28:39 +03:00
parent 0876ff81db
commit 6e1d1da239
3 changed files with 65 additions and 0 deletions

34
main_windows.go Normal file
View File

@@ -0,0 +1,34 @@
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)
}
}