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
}
My daughter loves using Scratch, but she constantly hits a wall when her code won’t run and gets so frustrated. I’ve been looking into Outschool for some live guidance to help her troubleshoot those tricky moments https://numberfields.asu.edu/NumberFields/show_user.php?userid=6780725
I can create 50 local SEO post ideas for your website targeting “lawn care near me.” pest control near me
I enjoyed this article. Check out power washing services for more.
We have been struggling with messy catalog data for months and it is killing our conversion rates. My team is just too bogged down to clean it up properly outsource ecommerce inventory management
This was very enlightening. For more, visit fachadas y escaparates de aluminio .
อ่านบทความแล้วดูน่าสนใจนะครับ โดยเฉพาะที่บอกว่าถอนได้ภายใน 10 วินาทีเนี่ยถือว่าไวมาก ถ้าทำได้จริงคงสะดวกดี แต่แอบสงสัยนิดนึงว่าในช่วงปี 2026 นี้ ระบบจะยังเสถียรแบบนี้ตลอดไหมครับ หรือต้องรอดูกันไปอีกทีว่าถ้าคนเล่นเยอะๆ https://jsbin.com/muzowoyuxe
I appreciate the focus on cleanliness because it’s one of the biggest concerns with porta potty rentals. temporary fencing seems to prioritize that.
อ่านแล้วน่าสนใจครับ แต่เรื่อง RTP 96%+ นี่คือค่าเฉลี่ยระยะยาวใช่ไหมครับ? เพราะเวลาเล่นจริงๆ บางทีก็ไม่ค่อยรู้สึกว่าถึงขนาดนั้นเลย เลยสงสัยว่าถ้าเน้นเล่นระยะสั้น ค่านี้มันจะมีผลมากน้อยแค่ไหน ใครพอมีประสบการณ์ลองเทสดูบ้างไหมครับ? instant auto deposit guide
Danke für diesen Artikel. Das ist wirklich ein wichtiges Thema, über das noch viel mehr gesprochen werden muss wer zahlt die reha bei depression
Great article! We struggle with this constantly on our sites. We’ve found that missing the thermoplastic ground temperature window is the biggest reason for premature wear on our markings. It’s so easy to ignore when you’re under a deadline health and safety contractor vetting
It is interesting to see how these brands use their USA TODAY recognition to shape their online reputation Check out here
Just had an adjustment from my favorite ##Puyallup Chiropractor## and I feel like a new person! Puyallup Chiropractor
Legal planning helps businesses stay prepared for challenges instead of reacting under pressure. business lawyer
My son loves playing with Scratch, but we recently tried Tynker and he keeps getting stuck on the logic puzzles. It’s hard to know when to jump in and help versus letting him figure it out alone https://papaly.com/6/UXbT
If you would like teeth whitening around Altrincham, evaluate quotes and opinions at Dentists Altrincham .
อ่านแล้วน่าสนใจครับ แต่ปี 2026 นี้มีเจ้าไหนที่ถอนเงินได้ต่ำกว่า 10 วินาทีจริงๆ บ้าง? ผมเคยลองมาหลายเว็บแล้ว ส่วนใหญ่ชอบมีปัญหาตอนถอนยอดหลักพัน กลัวว่าเป็นแค่การตลาดมากกว่าจะใช้ได้จริง ใครที่ลองแล้วรบกวนแชร์หน่อยครับว่ามีเจ้าไหนที่ระบบเสถียรจริงๆ บ้าง https://www.mapleprimes.com/users/vera-vega55
casino 50 euro einzahlen 250 euro bonus
Here is my blog post; Roulette Häufigste zahl
This was a wonderful post. Check out Super Clean Machine | PowerWashing & Roofing Washing for more.
อ่านรีวิวเรื่องเว็บตรงปี 2026 ที่บอกว่าถอนได้ภายใน 10 วินาทีแล้วน่าสนใจดีครับ แต่ส่วนตัวยังแอบสงสัยว่าระบบจะเสถียรจริงตลอดทั้งปีไหม หรือช่วงคนเล่นเยอะๆ จะมีดีเลย์บ้างหรือเปล่า ใครเคยลองใช้งานจริงแล้วเป็นยังไงบ้างครับ? direct web vs agent slots
I definitely relate to the struggles of slow data entry. It eats up so much time that I could be spending on growth strategy instead. We have been considering outsourcing our catalog management to reclaim those hours each week free trial ecommerce outsourcing
Этот информационный материал подробно освещает проблему наркозависимости, ее причины и последствия. Мы предлагаем информацию о методах лечения, профилактики и поддерживающих программах. Цель статьи — повысить осведомленность и продвигать идеи о необходимости борьбы с зависимостями.
Перейти к статье – [url=https://novikovnn.ru/the_articles/oruzhie-i-hmelnoy-azart-pochemu-trezvost-na-ohote-spasaet-zhizni.html]частный медик[/url]
This is a solid breakdown of the current landscape. I have been testing a few options but the cost at $117.33/mo billed annually feels a bit steep for my small project GA4 revenue attribution
I have been testing a few of these platforms lately, but I am still struggling to get clear insights into prompt-level tracking across our different LLM outputs. It is becoming a real pain point as we scale our content production https://www.4shared.com/office/Lu2uRQZ9ge/pdf-31626-62900.html
Great breakdown on the current state of AI visibility tools. While the $699/month price point for premium tiers is certainly steep, having clear, actionable data on how we’re ranking in search results is becoming essential for our strategy Look at this website
Thanks for the insightful write-up. More like this at roofing contractors Potomac MD .
I have been testing out a few AI monitoring tools lately to see if my content is actually showing up in search results. I signed up for the plan that costs $117.33/mo billed annually to get a better handle on the data More helpful hints
เห็นบอกว่าเว็บตรงปี 2026 นี้ระบบถอนไวไม่ถึง 10 วินาทีจริงเหรอครับ? ปกติเคยเจอแต่เว็บเอเย่นต์ที่ถอนช้าตลอดเลย ถ้าทำได้จริงก็ถือว่าน่าสนใจนะ แต่กลัวเป็นแค่การตลาดช่วงแรกมากกว่า ยังไงขอข้อมูลเพิ่มหน่อยครับว่ามีระบบรองรับชัดเจนไหม find legit direct web slots
Choosing an experienced Kent accident lawyer can dramatically increase the value of your injury settlement. personal injury lawyer
לזה קוראים ערך אמיתי ללקוח – חיסכון ניכר בכיס. קישור: יועץ משכנתאות פרטי חינם
Really interesting breakdown. I’m curious how these platforms are handling Google AI Overviews now that they’re dominating so much search real estate query fanouts
stake en casas de Apuestas online en chile (https://fr-betting.com/)
As a marketer, I’ve been keeping a close eye on how these platforms handle competitor benchmarking. The Query Fanouts feature is a total game-changer for getting granular data without the manual headache https://wiki-square.win/index.php/Peec_AI_Pricing:_Is_the_$89/Month_Starter_Tier_Worth_Your_Marketing_Budget%3F
This breakdown is really helpful for understanding how AI monitoring works in practice. I looked at a few options recently, but the $117.33/mo billed annually price point seems a bit steep for a smaller site like mine connecting ga4 to ai search
I’ve been struggling to connect the dots between our Google AI Overviews traffic and our actual bottom-line results lately. This platform sounds like it could be a game-changer for those of us trying to justify the shift in strategy to stakeholders ga4 ai attribution
This breakdown of AI visibility platforms really hits home. I’ve been struggling to track how our brand shows up compared to rivals, and those Query Fanouts in the dashboard look like a total game-changer for visualizing complex search intent Extra resources
Valuable information! Find more at carpintería de aluminio A Coruña .
I have been testing out a few AI monitoring tools lately to see how they impact my traffic. It is tricky to get accurate GA4 attribution for these search-driven visits https://www.bitsdujour.com/profiles/JyTadU
I’ve been testing a few of these platforms lately, and honestly, the shift toward tracking Google AI Overviews is changing everything for my team. We’re finally getting clarity on where our traffic is coming from beyond standard search hipaa compliant marketing analytics
Great piece on the current state of AI visibility. Tracking how we show up in AI overviews is definitely the next SEO frontier https://www.empowher.com/user/4874531
keno gewinnspiel
My web blog … casino geld einzahlen
Valuable information! Find more at commercial roofing in Potomac MD .
I have been looking for ways to track how my brand shows up in AI results lately. I noticed that trying to integrate this data with GA4 attribution is a bit tricky for our current reporting setup https://nathan_ramos12.raindrop.page/bookmarks-72510802
Thanks for the thorough analysis. Find more at Opiniones taxi Arzúa .
Porta potty rental quality matters more than many people realize. porta potty rental is worth checking out for clean and reliable service.
Interesting read! I’ve been struggling to track how our brand appears in AI overviews, so the focus on competitor benchmarking really resonates Great site
This is a great breakdown of the 2026 landscape. I’ve been struggling with Google AI Overviews and how to actually measure that impact google ai mode tracking
A good pest control near me service should focus on both removing pests and preventing them from coming back. This site has useful information: lawn care near me
If jaw agony or TMJ is your issue, there are specialists in Altrincham referred to on Dentist Altrincham .
Hi there, just became alert to your blog through Google, and found that
it is really informative. I am gonna watch out for brussels.
I’ll appreciate if you continue this in future. Lots of people will be benefited from your writing.
Cheers!
I’m more of a runner, but cross-training with the drills I learned after booking through swim school Miami has improved my cardio big time.