initial commit
This commit is contained in:
34
main_windows.go
Normal file
34
main_windows.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user