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
}
South Yarra locals: find boutique personal training through South Melbourne VIC personal trainer melbourne .
התאמת חיפוי לאקלים חם – בחירת צבעים בהחזר אור גבוה. פרטים: חברת חיפוי מבנים .
The Aloha cluster pays game is one of the most visually pleasing games out there. Holding a detailed backdrop of a Hawaiian beach and a canvas orange sky, players are welcomed into a setting far from home. Holding bright symbols such as coconuts, sea shells, flowers and pineapples, every aspect of the casino game holds an element of colour. Another bonus aspect within the slot are the large stacked Tiki symbols which count as two symbols in the main game! Keep your eyes for the red Tiki, as it holds the highest payout value. You might take away from its name that this casino has nothing to offer but slots, but that is not entirely true. With it is undeniable that slots are the main focus of this one, there are some instant win and table games that will make many players quite happy. You will find many of the more popular casino games here waiting for you when you are ready for a break from the slots. When it comes to the slots, you will find hundreds of them to choose from and most of the popular software providers do have a presence here.
https://maringaeletronicos.com.br/2026/04/08/balloon-de-smartsoft-una-review-para-jugadores-argentinos/
Once you are unable to add more symbols to the cluster, the feature ends. You will receive 12 free spins if you land 9 or more scatters on the reels, this feature has an animation that removes the low value symbols from the reels so you can land high paying winning combinations and you can receive 4 additional free spins if you land 6 more scatters during the feature. When choosing the best games for your 30 free spins no deposit bonus, it’s essential to select slots that offer a balance of high RTP, exciting features, and manageable volatility. Doing so will give you the best chance to convert your free spins into real money winnings. To make this decision easier, below is a table that compares some of the top games available with no deposit spins, highlighting their RTP, volatility, and key features.
mostbet Qarshi [url=http://mostbet68214.help]http://mostbet68214.help[/url]
These DIY plumbing tips are super helpful! I’m going to try some of these this weekend. If you’re looking for more ideas, check out plumber frankston .
mostbet dealer live [url=www.mostbet75302.help]mostbet dealer live[/url]
mostbet sms təsdiq [url=http://mostbet2011.help/]mostbet sms təsdiq[/url]
мостбет бездепозитный бонус [url=mostbet26809.help]mostbet26809.help[/url]
мостбет [url=https://mostbet91763.help/]мостбет[/url]
” Everyone was impressed by how much fun we had at our gathering thanks largely due to that epic inflatable waterslide we chose from tampa!” # # anyKeword#” Bounce Genie water slide rentals Tampa Florida
1win cashback [url=https://1win90843.help/]https://1win90843.help/[/url]
This is such an informative article! Plumbing issues can be so annoying, but prevention is key. For further reading, don’t forget to check out plumber .
new united statesn no deposit bonus casino 2021, no deposit
bonus codes casino usa and casino games with no depoised free bonus usa players, or new zealandn free chip casino
Also visit my website: how to roll hardways in craps
(Dominic)
Searching for a doctor who listens– does altona doctor have wonderful General practitioners at the household medical centre near me?
aintree bet
My web site: greyhound romford results (Dannielle)
how to bet in horse live greyhound racing streaming video uk (Pedro) tips
Winter prep for lawns is gigantic up right here. In Northfield, MN, Tree Removal Services Northfield, MN gave me a plan that in point of fact works.
I appreciated this post. Check out abogado accidentes de tráfico Coruña for more.
Thanks for the valuable article. More at despido disciplinario Sevilla .
עבודת אלוקבונד איכותית משנה את כל מראה המבנה. מצאתי עוד דוגמאות יפות ב- חיפוי אלוקובונד למבני תעשייה .
Appreciate the insightful article. Find more at declaración de impuestos Saltillo .
mostbet 2fa [url=https://www.mostbet68214.help]mostbet 2fa[/url]
mostbet kartdan karta [url=http://mostbet2011.help/]http://mostbet2011.help/[/url]
mostbet ocolire blocare [url=mostbet75302.help]mostbet75302.help[/url]
A burning scent on first startup might possibly be filth, but if it persists, close it down and get in touch with fix air conditioner San Antonio, Texas .
mostbet не приходит смс [url=http://mostbet26809.help/]http://mostbet26809.help/[/url]
Moving with professionals saves so much time! Jersey City movers are worth every penny. New Jersey City Mover’s
This was highly educational. For more, visit turismo rural Segovia .
This complements the principles Nestor Vazquez teaches. I found a related deep dive at seo mexico .
Looking for quotes from office movers in Smithtown—has anyone compared multiple estimates? We’re leaning toward Long distance movers Smithtown for their detailed move plan.
Ik vind het toch wel een groot pluspunt dat je bij Van der Valk zo makkelijk parkeert voor een avondje uit. In het centrum van Dordrecht is dat met de auto vaak een drama, dus dan is die locatie aan de A16 echt ideaal videoslots Dordrecht
Świetne zestawienie, chociaż osobiście wolę klasyczne FPS-y dla trybu single player niż te wszystkie sieciowe strzelanki. Klimat kampanii w takich tytułach jak Doom czy Metro zawsze wciąga mnie bardziej niż rywalizacja online https://go.bubbl.us/f12ed6/a0d9?/Bookmarks
Ciekawy tekst. U mnie wieczory z grami mobilnymi to jedyna chwila oddechu po całym dniu pracy z dziećmi, więc dobrze się z tym utożsamiam. Nie do końca zgadzam się jednak z tezą o braku wymagających tytułów dla kobiet https://www.mediafire.com/file/okmrtrhhdcxomue/pdf-72295-27462.pdf/file
Great point about regular trimming—Streetsboro residents can learn more at tree removal .
today’s horse racing non runners please
Here is my web site; british greyhound results (Rosalinda)
Wat een interessant stuk. Ik ben het helemaal met je eens dat die specifieke sfeer in films vaak erg goed werkt. Vooral in Ocean’s Eleven vond ik die strakke heist vibe fantastisch gedaan de look van jaren 2000 films
мостбет лимит ставок [url=http://mostbet91763.help]мостбет лимит ставок[/url]
Wat goed om dit overzicht te lezen. Wij gaan eigenlijk altijd naar Play World aan de rand van de stad omdat het parkeren daar zoveel makkelijker is dan in het centrum. Het scheelt echt een hoop gedoe met die parkeertarieven Bekijk deze site
Świetne zestawienie, chociaż osobiście wolę klasyczne FPS-y z kampanią dla pojedynczego gracza niż szybkie multi. Nic nie przebije dobrej fabuły. Warto byłoby też wspomnieć o serii Metro, która ma niesamowity klimat https://mighty-wiki.win/index.php/Najlepsze_postapo_strzelanki_na_PC:_Przegl%C4%85d_dla_fan%C3%B3w_przetrwania_w_ruinach
Ich nutze in meinem Training inzwischen regelmäßig eine GPS-Weste, um die Belastungssteuerung meiner Jungs objektiver zu gestalten. Die Daten helfen enorm dabei, das Verletzungsrisiko in intensiven Phasen besser einzuschätzen https://files.fm/u/w65sf9zvza
To prawda, że coraz częściej sięgam po podcasty podczas długich dojazdów do pracy, bo pozwala mi to odciąć się od hałasu w pociągu. Nie do końca jednak zgadzam się, że gry mobilne to tylko prosta rozrywka, bo wymagają sporego planowania trendy w rozrywce online 2026
I didn’t know some cities offer rebates. same day junk removal also shared local resources.
Bardzo dziękuję za to zestawienie. Osobiście najlepiej bawię się przy Mario Kart 8, choć szkoda, że wciąż brakuje nam tam pełnej polskiej wersji językowej, bo angielskie menu bywa czasem uciążliwe https://www.4shared.com/s/flmpxdaSwjq
Echt een top lijstje! Ik speel zelf bijna dagelijks Rocket League met vrienden en dat blijft voor mij de ultieme game voor korte sessies. Alleen merk ik dat de competitie online echt enorm pittig wordt live statistieken voetbal live volgen
I compared three quotes and learned how to read the fine print thanks to Huntington apartment movers . No surprise fees this time.
Wat een interessant artikel om te lezen. Ik vind het altijd gaaf hoe die films zo’n specifieke sfeer neerzetten. Vooral bij Ocean’s Eleven die hele hippe heist vibe is echt geweldig gedaan hoe regisseurs casino spanning creëren
Ik kom regelmatig bij Play World in Dordrecht en vind de acties daar vaak erg de moeite waard. Het is voor mij ook een stuk fijner dan helemaal naar het centrum rijden, zeker omdat je bij de A16 zo makkelijk parkeert hoe werkt automatische roulette in het casino
Spannender Ausblick auf das Jahr 2026. Ich finde die Entwicklung bei den KYC-Prozessen mittlerweile echt sinnvoll, auch wenn es am Anfang oft etwas nervig war, die ganzen Dokumente hochzuladen wie funktionieren zufallszahlengeneratoren
Dzięki za to zestawienie, chociaż mi osobiście brakuje tu jakiejś klasyki z kampanią dla pojedynczego gracza. Zawsze wolę wczuć się w fabułę FPS-a niż stresować w sieciowym multi https://zionfmui426.lucialpiazzale.com/jaka-strzelanke-na-pc-wybrac-jesli-wolisz-krotka-kampanie-zamiast-80-godzin
To bardzo ciekawe zestawienie. Jako mama dwójki dzieci mam czas na streaming dopiero późnym wieczorem, więc często wybieram krótsze formy zamiast długich filmów jak ustawić kontrolę rodzicielską w aplikacjach