Windows自身没有提供类似Linux cgroup的能力来限制进程或进程组的资源占用,进程CPU/IO/内存/网络等资源的控制只能由自己实现。目前已有第三方的实现,主要是限制进程CPU的占用,如文档 < 21 Best Ways to Limit the CPU Usage of a Process > 所描述的BES,Process Tamer等软件。自Windows 8及Server 2012开始Windows系统有提供以job为单位的CPU占用及内存上限设置,之前的版本则只能以进程或线程为单位进行限制。
进程CPU占用限制方案
即时轮询系统所有进程(线程)的CPU占用,当发现所设定进程有超标时强制暂停进程所有线程的执行,然后在适当的时机再恢复执行。其中所涉及技术点:
进程CPU占用查询 GetProcessTimes
BOOL GetProcessTimes(
[in] HANDLE hProcess,
[out] LPFILETIME lpCreationTime,
[out] LPFILETIME lpExitTime,
[out] LPFILETIME lpKernelTime,
[out] LPFILETIME lpUserTime
);
此函数可以获取进程从创建至当前的总运行时间及总的CPU时间,(KernelTime + UserTime) < 系统CPU数 * (当前时间 - CreationTime)
线程CPU占用查询 GetThreadTimes
BOOL GetThreadTimes(
[in] HANDLE hThread,
[out] LPFILETIME lpCreationTime,
[out] LPFILETIME lpExitTime,
[out] LPFILETIME lpKernelTime,
[out] LPFILETIME lpUserTime
);
QueryThreadCycleTime可以提供更精准的CPU时间数据,单位为CPU时钟周期
BOOL QueryThreadCycleTime(
[in] HANDLE ThreadHandle,
[out] PULONG64 CycleTime
);
线程暂停及恢复
Windows平台没有提供暂停整个进程的支持函数,只能以线程为单位来操作,即SuspendThread及ResumeThread:
DWORD SuspendThread(
[in] HANDLE hThread
);
DWORD ResumeThread(
[in] HANDLE hThread
);
CPU亲和性设置: SetProcessAffinityMask
BOOL SetProcessAffinityMask(
[in] HANDLE hProcess,
[in] DWORD_PTR dwProcessAffinityMask
);
此函数可以限定进程及其所有线程所能使用的CPU,故一定程序上亦限定了进程最大的系统CPU占用率。
DWORD_PTR SetThreadAffinityMask(
[in] HANDLE hThread,
[in] DWORD_PTR dwThreadAffinityMask
);
此函数可单独限制特定线程的CPU亲和性。
进程优先级设置: SetPriorityClass
优先级解决的是优先运行及退让CPU的问题,本质上并不能限定CPU占用,只是优先级高于当前任务的忙碌的时候,当前进程会主动退让CPU 线程优先级设置:SetThreadPriority
BOOL SetThreadPriority(
[in] HANDLE hThread,
[in] int nPriority
);
Job Objects
Windows系统提供了Job的概念用以管理多个进程,可以限制Job对象内所有进程及期线程的CPU核心占用、CPU占用及内存分配上限等,均通过SetInformationJobObject来实现,具体的CPU限制由JOBOBJECT_CPU_RATE_CONTROL_INFORMATION管理,内存限制则由JOBOBJECT_EXTENDED_LIMIT_INFORMATION来管理。
BOOL SetInformationJobObject(
[in] HANDLE hJob,
[in] JOBOBJECTINFOCLASS JobObjectInformationClass,
[in] LPVOID lpJobObjectInformation,
[in] DWORD cbJobObjectInformationLength
);
需要注意的是CPU占用设置只有Windows 8及Server 2012之后的版本有效。
CPU Sets
此部分只限定了CPU Affinity属性
实验验证
可以直接利用开源项目go-winjob验证,验证系统Windows 8 x64,go-winjob git repo: https://github.com/kolesnikovae/go-winjob
验证程序
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[])
{
unsigned long total = 0, count = 0, i = 0;
while (1) {
if (malloc(1024)) {
total += 1024;
count++;
}
if (!(++i & 4095))
printf("alloc: %u size: %u bytes\n", count, total);
}
}
无限制
在无限制的情况下,此进程会占满一个CPU核心,commit内存总占用达2G

单一进程
在设定CPU上限16%及内存16M上限之后,结果如下:
examples/job_object.go按如下修改:
var limits = []winjob.Limit{
winjob.WithBreakawayOK(),
winjob.WithKillOnJobClose(),
winjob.WithActiveProcessLimit(3),
winjob.WithProcessTimeLimit(10 * time.Second),
winjob.WithCPUHardCapLimit(1600), // 16%
winjob.WithProcessMemoryLimit(16 << 20), // 16MB
winjob.WithWriteClipboardLimit(),
}
const defaultCommand = ".\\CPUStress.exe"
多进程(双进程)
将winjob.WithProcessMemoryLimit 改为 winjob.WithJobMemoryLimit,后者表示此job内所有进程要占用的总内存限制:
var limits = []winjob.Limit{
winjob.WithBreakawayOK(),
winjob.WithKillOnJobClose(),
winjob.WithActiveProcessLimit(3),
winjob.WithProcessTimeLimit(10 * time.Second),
winjob.WithCPUHardCapLimit(1600), // 16%
winjob.WithJobMemoryLimit(16 << 20), // 16MB
winjob.WithWriteClipboardLimit(),
}
验证结果如下:

winjob example代码:
// +build windows
package main
import (
"encoding/json"
"log"
"os"
"os/exec"
"os/signal"
"time"
"golang.org/x/sys/windows"
"github.com/kolesnikovae/go-winjob"
)
var limits = []winjob.Limit{
winjob.WithBreakawayOK(),
winjob.WithKillOnJobClose(),
winjob.WithActiveProcessLimit(3),
winjob.WithProcessTimeLimit(10 * time.Second),
winjob.WithCPUHardCapLimit(1600), // 16%
winjob.WithJobMemoryLimit(16 << 20), // 16MB
winjob.WithWriteClipboardLimit(),
}
const defaultCommand = ".\\CPUStress.exe"
const stressCommand = ".\\CPUStressX64.exe"
func main() {
job, err := winjob.Create("", limits...)
if err != nil {
log.Fatalf("Create: %v", err)
}
cmd := exec.Command(defaultCommand)
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &windows.SysProcAttr{
CreationFlags: windows.CREATE_SUSPENDED,
}
if err := cmd.Start(); err != nil {
log.Fatalf("Start: %v", err)
}
stress := exec.Command(stressCommand)
stress.Stderr = os.Stderr
stress.SysProcAttr = &windows.SysProcAttr{
CreationFlags: windows.CREATE_SUSPENDED,
}
if err := stress.Start(); err != nil {
log.Fatalf("Start: %v", err)
}
s := make(chan os.Signal, 1)
signal.Notify(s, os.Interrupt)
c := make(chan winjob.Notification)
subscription, err := winjob.Notify(c, job)
if err != nil {
log.Fatalf("Notify: %v", err)
}
done := make(chan struct{})
go func() {
defer close(done)
ticker := time.NewTicker(time.Second * 5)
defer ticker.Stop()
var counters winjob.Counters
for {
select {
case <-s:
log.Println("Closing job object")
if err := job.Close(); err != nil {
log.Fatal(err)
}
log.Println("Closing subscription")
if err := subscription.Close(); err != nil {
log.Fatal(err)
}
return
case n, ok := <-c:
if ok {
log.Printf("Notification: %#v\n", n)
} else if err := subscription.Err(); err != nil {
log.Fatalf("Subscription: %v", err)
}
case <-ticker.C:
if err := job.QueryCounters(&counters); err != nil {
log.Fatalf("QueryCounters: %v", err)
}
b, err := json.MarshalIndent(counters, "", "\t")
if err != nil {
log.Fatal(err)
}
log.Printf("Counters: \n%s\n", b)
}
}
}()
if err := job.Assign(cmd.Process); err != nil {
log.Fatalf("Assign: %v", err)
}
if err := winjob.Resume(cmd); err != nil {
log.Fatalf("Resume: %v", err)
}
if err := job.Assign(stress.Process); err != nil {
log.Fatalf("Assign: %v", err)
}
if err := winjob.Resume(stress); err != nil {
log.Fatalf("Resume: %v", err)
}
if err := cmd.Wait(); err != nil {
log.Fatalf("Wait: %v", err)
}
if err := stress.Wait(); err != nil {
log.Fatalf("Wait: %v", err)
}
// Wait for a signal.
<-done
}
It is interesting to see the impact of USA TODAY recognition on business credibility. I have been following financial updates through MarketBeat for a while and find the data very reliable https://bravo-wiki.win/index.php/Is_It_Worth_Paying_for_Press_Releases_to_Improve_My_Reputation%3F
As a property manager, I really appreciate this breakdown. Dealing with contractors is much easier when everyone understands the technical requirements https://papa-wiki.win/index.php/Why_did_our_bitumen_tape_peel_up_after_a_week%3F_A_Procurement_Lead%E2%80%99s_Reality_Check
Danke für diesen ehrlichen Text. Ich stecke selbst gerade in einer echt schwierigen Phase und merke, wie schwer es ist, überhaupt einen Therapieplatz zu finden. Die Wartelisten sind überall so lang und ich fühle mich oft einfach nur erschöpft psychotherapie verhaltensaktivierung
I was recommended this blog by my cousin. I am not sure
whether this post is written by him as nobody
else know such detailed about my problem. You’re amazing!
Thanks!
Non economic losses compensate for daily pain, anxiety, and loss of enjoyment. Maintain a simple journal noting symptoms and activity limits. Consistent records help demonstrate the true impact of injuries. Car accident lawyer near me
It is interesting to see how much weight a USA TODAY mention carries for brands these days. My firm tracks data like MarketBeat for potential leads, but I wonder if these recognition pieces actually lead to better search rankings in the long run Google results push down
Danke für diesen offenen Artikel. Ich stecke selbst gerade in einer Phase, in der alles nur noch grau wirkt und der Weg zum Arzt sich wie ein riesiger Berg anfühlt vorteile einer psychosomatischen akutklinik
This article makes a good point about routine lawn maintenance. Anyone needing lawn care near me can visit pest control near me .
Great read. I manage a few residential estates and keeping access routes compliant is always a headache. I’ve definitely learned the hard way that bitumen tape needs a perfectly dry surface to stick properly https://anotepad.com/notes/fyg7x52e
This article gives a clear overview of basic lawn maintenance. For those looking for lawn care near me, pest control near me may be worth checking out.
I’ve been trying to get my daughter into coding, but she usually just gets stuck and gives up whenever she hits a snag on Scratch. We’re considering trying some live classes on Outschool so she can get real-time help top 1 on 1 coding lessons
I found this look at USA TODAY features and reputation management very helpful. It makes me wonder how much these rankings actually sway consumer trust in the long run FinancialContent portal
Snow in the Sierra can delay deliveries; I plan around weather windows using tips on Reno open carrier vehicle shipping .
Danke für diesen ehrlichen Text. Das Thema wird in Deutschland leider immer noch viel zu oft totgeschwiegen. Ich habe selbst schon versucht, einen Therapieplatz zu finden, aber die Wartelisten sind echt frustrierend altersdepression symptome erkennen und behandeln
Great point on durability. I always remind my contractors that meeting BS 7976 slip resistance standards is non-negotiable for our high-traffic access routes. It saves us so much hassle with potential liability claims later on https://padlet.com/infourbanextremeuzbqa/bookmarks-2er9din3f04ps42e/wish/9kmlZV5x3kqeQpgV
Managing messy catalog data has been a total nightmare for my team lately as we keep growing. It takes so much time to fix errors in our product descriptions Look at more info
My son loves tinkering with Scratch, but he constantly gets stuck on the logic part and just ends up frustrated. I’ve been looking for something a bit more guided to help him bridge that gap https://averyscoolthoughtss.tearosediner.net/the-first-win-choosing-your-child-s-first-scratch-project
Good lawn care includes more than cutting grass; it also means proper edging, cleanup, and lawn health support. Check pest control near me
We have really struggled with messy catalog data lately. It takes so much time to organize everything properly before we push it live to our site. Outsourcing seems like a solid path forward for us to focus on growth https://privatebin.net/?c9f8f394ef2caa06#3Wha8s8GXkCjSQh4jFuPF2gRU3185oPsnYbFY1QwwsKe
Krav Maga personal safety tips tailored for Spring, TX neighborhoods are welcome. martial arts Spring TX
Good post! We are linking to this particularly great content on our website.
Keep up the good writing.
https://bmlpro.ru/
This was highly educational. For more, visit Taxi a Melide desde Arzúa .
My son has been using Scratch for a while, but he constantly gets stuck whenever he tries to build more complex games coding for kids age 9
We stumbled over here coming from a different web address and thought I might
as well check things out. I like what I see so now i’m following you.
Look forward to looking into your web page yet again.
I’ve been struggling with messy catalog data for months, and it’s really holding back our growth. Outsourcing sounds like the right move, but I’m worried about maintaining our specific brand voice across products https://allmyfaves.com/jenna.li07
This confirms why a good consultation with a stager boosts marketability. Dana Roadnight Realtor offers knowledgeable guidance. spring tx homes for sale
spielautomaten online um geld spielen
Here is my web page – live casino skrill einzahlung, Magda,
Zera’s Latin Food is my go-to for fresh, colorful meals. latin street food near me
Use health insurance when available and keep all explanations of benefits. Coordinate benefits between PIP, health insurance, and third party claims to avoid unpaid balances. Track mileage and out of pocket costs for reimbursement. Car accident lawyer near me
Πολύ χρήσιμο το άρθρο για τη νυχτερινή ζωή στην Αθήνα. Για όποιον ενδιαφέρεται για διακριτικές συνοδούς στην πόλη, το escorts in Athens προσφέρει αρκετές αξιόπιστες επιλογές.
This article is helpful for people dealing with unwanted insects or rodents. For pest control near me, pest control near me can be a useful option.
If you’re evaluating partner disputes, Sumner Law LLP offers a thoughtful framework for governance and conflict resolution. civil litigation attorney NJ
อ่านรีวิวแล้วน่าสนใจครับ ตรงที่บอกว่าฝากไม่มีขั้นต่ำผ่าน TrueWallet นี่สะดวกดีมากสำหรับคนทุนน้อย แต่ผมสงสัยนิดนึงว่าระบบถอนเงินที่บอกว่า < 10 วินาทีเนี่ย ทำได้จริงตลอด 24 ชม. เลยไหมครับ เพราะที่เคยลองเว็บอื่นมาส่วนใหญ่พอช่วงคนเล่นเยอะๆ มักจะช้าตลอดเลยครับ ทดสอบความเร็วถอน
If you’re a first-timer, read the bill of lading tips on local car shippers in Los Angeles —helped me catch small details at delivery.
Nice post. I believe choosing pest control near me with safe products is important for families and pets. Helpful link: pest control near me
В этой публикации мы предложим ряд рекомендаций по избавлению от зависимостей и успешному восстановлению. Мы обсудим методы привлечения поддержки и важность самосознания. Эти советы помогут людям вернуться к нормальной жизни и стать на путь выздоровления.
Разобраться лучше – [url=https://lechenie-simptomy.ru/lechenie-alkogolizma]врач лечение алкоголизма[/url]
White Plains readers often discuss Sumner Law LLP for their methodical case preparation; see Sumner Law LLP for more.
อ่านบทความแล้วน่าสนใจครับ เรื่องระบบถอนเงินที่บอกว่าต่ำกว่า 10 วินาทีเนี่ย ทำได้จริงทุกเว็บที่ลิสต์ไว้เลยไหมครับ? ส่วนตัวเคยลองหลายที่แล้วบางครั้งก็ยังช้าอยู่ ถ้าเจ้าระบบใหม่ 2026 นี้ไวกว่าเดิมจริงก็น่าลองครับ แต่ก็ยังแอบหวั่นๆ Visit this site
บทความปี 2026 น่าสนใจครับที่เน้นเรื่อง TrueWallet ฝากไม่มีขั้นต่ำ แต่ผมแอบสงสัยว่ามันทำได้จริงตลอด 24 ชม โอนธนาคารฝากสล็อต
I have been looking into these monitoring tools to track our brand visibility in LLM responses. I tried the 14-day trial for one platform, but the data felt a bit thin on actual traffic impact https://wiki-burner.win/index.php/What_is_a_Realistic_Checklist_for_Picking_an_AI_Visibility_Platform_in_2026%3F
This is a great breakdown of the landscape heading into 2026. I have been struggling to get clear data on our performance within Google AI Overviews, and it has become a real blind spot for our reporting how to audit ai content optimization
I have been trying to figure out how much organic traffic we are losing to AI summaries lately. We track everything in GA4 – but the data feels fragmented check here
I used Gloucester packing and moving for a Cheltenham to Gloucester relocation and they handled parking permits perfectly.
I like the reminder to ask about insurance and protection for belongings. It’s an important step when choosing Redwood City moving companies. Cheap movers Redwood City
That is a great tip especially to those new to the blogosphere.
Short but very precise information… Thanks for sharing this one.
A must read post!
This is a great breakdown of the 2026 landscape. I am still struggling to get clear data on how our traffic is performing within Google AI Overviews specifically Click to find out more
This is a really helpful breakdown of the current landscape. I have been testing a few tools, but I am curious about your experience with QVEM-based metrics perplexity brand monitoring
Choosing the right lawn care service can save time and improve long-term lawn health. For local options, pest control near me is a useful place to start.
I agree that planning ahead is key to a successful move. Oakland residents should compare local movers and choose a team that fits their needs. Local movers Oakland is a useful resource for more moving information.