减慢 Windows 进程的速度?

发布于 2024-09-29 17:08:15 字数 120 浏览 3 评论 0原文

如何减慢 Windows 进程的速度?

我知道我需要挂钩 QueryPerformanceCounter 但接下来我需要做什么?

需要 Delphi 或 C++ 的帮助

How can I slow down a Windows Process?

I understand that I need to hook QueryPerformanceCounter but what do I need to do next?

Need help for Delphi or C++

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤檠 2024-10-06 17:08:15

我不确定我是否理解挂钩 QueryPerformanceCounter 与减慢您所描述的进程之间的关系。也许如果您详细说明原来的问题或评论,我可以进一步帮助您。

要回答您的问题,您可以使用 Windows 2000 资源工具包中的 cpustres.exe 给系统施加负载,从而导致上下文切换。如果您放置足够的负载并超额订阅所有可用的 CPU,您的进程将会减慢。根据您使用 cpustres 设置选择的负载级别,您可以或多或少地减慢进程速度。

如果您想以更受控的方式以编程方式减慢进程而不使其崩溃(如果是游戏),您可以使用卡萨布兰卡的答案,但将 Sleep(10) 替换为:

// Turn off optimizations to make sure the busy wait loops do
// not get optimized out!

HANDLE hThread = ...; // thread that you want to slow down 
for (;;) { 
  SuspendThread(hThread); // Do this for each process thread

  // Busy wait for pause (possibly small)
  const DWORDLONG pauseFactor=1000; // In cycles
  DWORDLONG start=__rdtsc();

  while (__rdtsc()-start<pauseFactor)
    ;  

  ResumeThread(hThread); // Do this for each process thread

  // Busy wait for resume
  const DWORDLONG runFactor=1000; // In cycles
  DWORDLONG start=__rdtsc();

  while (__rdtsc()-start<runFactor)
    ;  
} 

I am not sure I understand the relationship of hooking QueryPerformanceCounter to slowing down a process that you described. Perhaps if you elaborate in the original question or a comment, I can help you further.

To answer your question, you can use cpustres.exe from the Windows 2000 resource kit to put a load on your system, causing context switching. If you put enough of a load and oversubscribe all available CPUs, you will slow down your process. Depending on the load level you select with the cpustres settings, you can slow your process down a lot or a little.

If you want to slow down the process programmatically in a more controlled way without crashing it if it is a game, you can use casablanca's answer, but replace Sleep(10) with:

// Turn off optimizations to make sure the busy wait loops do
// not get optimized out!

HANDLE hThread = ...; // thread that you want to slow down 
for (;;) { 
  SuspendThread(hThread); // Do this for each process thread

  // Busy wait for pause (possibly small)
  const DWORDLONG pauseFactor=1000; // In cycles
  DWORDLONG start=__rdtsc();

  while (__rdtsc()-start<pauseFactor)
    ;  

  ResumeThread(hThread); // Do this for each process thread

  // Busy wait for resume
  const DWORDLONG runFactor=1000; // In cycles
  DWORDLONG start=__rdtsc();

  while (__rdtsc()-start<runFactor)
    ;  
} 
谷夏 2024-10-06 17:08:15

我能想到的一种方法是使用专用线程 SuspendThread 在您想要减慢速度的线程上,等待一会儿,然后恢复线程:

HANDLE hThread = ...; // thread that you want to slow down
for (;;) {
  SuspendThread(hThread);
  Sleep(10); // some number of milliseconds - larger values will slow down more
  ResumeThread(hThread);
}

One way I can think of is to have a dedicated thread use SuspendThread on the thread that you want to slow down, wait for a little while and then resume the thread:

HANDLE hThread = ...; // thread that you want to slow down
for (;;) {
  SuspendThread(hThread);
  Sleep(10); // some number of milliseconds - larger values will slow down more
  ResumeThread(hThread);
}
女中豪杰 2024-10-06 17:08:15

我不明白你的问题的动机/背景是什么,因为你没有解释清楚。但是,使用 SetPriorityClass(),可以将指定进程的优先级设置为BELOW_NORMAL_PRIORITY_CLASS,甚至设置为IDLE_PRIORITY_CLASS,使进程运行速度变慢;您还可以将指定进程的优先级设置为ABOVE_NORMAL_PRIORITY_CLASS,甚至设置为HIGH_PRIORITY_CLASS,以便进程运行得更快。在此之前,您需要通过 PID 获取目标进程的句柄,请查看此处。

I don't understand what is the motive/background of your question since you didn't explain it clearly. However, using SetPriorityClass(), you can sets the priority class for the specified process to BELOW_NORMAL_PRIORITY_CLASS or even to IDLE_PRIORITY_CLASS so that the process running slower; and you can also sets the priority class for the specified process to ABOVE_NORMAL_PRIORITY_CLASS or even to HIGH_PRIORITY_CLASS so that the process running faster. Before doing that, you'll need to get handle of target process by its PID, look here.

橪书 2024-10-06 17:08:15

Windows 2000 在内部进程管理上引入了一个新层,允许对一个或多个进程设置额外的限制:作业。我不确定它是否允许设置所用处理器时间的限制,但如果应用程序尚未使用该方法,您可能只能调用 AssignProcessToJobObjectSetInformationJobObject 施加额外的限制。

Windows 2000 introduced a new layer over internal process management that allows to set extra limits on one or more processes: Jobs. I'm not sure if it allows to set a limit on processor time used, but if the application isn't using the method already, you might just be able to call AssignProcessToJobObject and SetInformationJobObject to impose extra limitations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文