From: Bart on
Hello,

I have an application that is constantly running at 100% CPU and
causing everything to be sluggish. Another GUI application runs at the
same time and needs to be responsive. I do not have sources for either
of these applications. Now, reducing the priority of the CPU hogging
process does not help much. Normally, the GUI application should only
yield the CPU when it doesn't have any more events to process, but
since I don't have the sources I can't say for sure.

Anyhow, I would like to write my own fix for this situation. I was
wondering if there is any way to force another process to sleep for a
few milliseconds or limit the amount of CPU time it gets. Is such a
thing even possible?

Thanks.
From: roger.orr on
On Jun 25, 9:42 am, Bart <bart.kowal...(a)gmail.com> wrote:
> Hello,
>
> I have an application that is constantly running at 100% CPU and
> causing everything to be sluggish. Another GUI application runs at the
> same time and needs to be responsive. I do not have sources for either
> of these applications. Now, reducing the priority of the CPU hogging
> process does not help much. Normally, the GUI application should only
> yield the CPU when it doesn't have any more events to process, but
> since I don't have the sources I can't say for sure.
>
> Anyhow, I would like to write my own fix for this situation. I was
> wondering if there is any way to force another process to sleep for a
> few milliseconds or limit the amount of CPU time it gets. Is such a
> thing even possible?
>
> Thanks.

It is possible -- one way would be to use SuspendThread() /
ResumeThread() on the errant process.
This sort of thing is obviously a bit of a 'last resort'!

Roger.
From: RFOG on
You only need to put at least one Sleep(<milliseconds>) on each offending
process into thread loop.

<milliseconds> depends on the priority of your thread, but putting 1 it is
enough to give a chance to other windows apps.

void MyThread(DWORD)
{
while(!terminate)
{
Sleep(1);
//Do work
}
}


"Bart" <bart.kowalski(a)gmail.com> escribi� en el mensaje de noticias
news:1d8576f4-de2d-4a45-b4d6-eafd510e4607(a)m3g2000hsc.googlegroups.com...
> Hello,
>
> I have an application that is constantly running at 100% CPU and
> causing everything to be sluggish. Another GUI application runs at the
> same time and needs to be responsive. I do not have sources for either
> of these applications. Now, reducing the priority of the CPU hogging
> process does not help much. Normally, the GUI application should only
> yield the CPU when it doesn't have any more events to process, but
> since I don't have the sources I can't say for sure.
>
> Anyhow, I would like to write my own fix for this situation. I was
> wondering if there is any way to force another process to sleep for a
> few milliseconds or limit the amount of CPU time it gets. Is such a
> thing even possible?
>
> Thanks.

--
Microsoft Visual C++ MVP
========================
Mi blog sobre programaci�n: http://geeks.ms/blogs/rfog
Momentos Leves: http://momentosleves.blogspot.com/
Cosas m�as: http://rfog.blogsome.com/
Libros, ciencia ficci�n y programaci�n
========================================
Cualquier problema sencillo se puede convertir en insoluble si se celebran
suficientes reuniones para discutirlo.
-- Regla de Mitchell.

From: Bart on
Like I wrote in my post, I do not have the source code of the
offending process.

Thanks.


On Jun 25, 12:23 pm, "RFOG" <n...(a)mail.com> wrote:
> You only need to put at least one Sleep(<milliseconds>) on each offending
> process into thread loop.
>
> <milliseconds> depends on the priority of your thread, but putting 1 it is
> enough to give a chance to other windows apps.
>
> void MyThread(DWORD)
> {
> while(!terminate)
> {
> Sleep(1);
> //Do work
> }
>
> }
>
> "Bart" <bart.kowal...(a)gmail.com> escribió en el mensaje de noticiasnews:1d8576f4-de2d-4a45-b4d6-eafd510e4607(a)m3g2000hsc.googlegroups.com...
>
>
>
> > Hello,
>
> > I have an application that is constantly running at 100% CPU and
> > causing everything to be sluggish. Another GUI application runs at the
> > same time and needs to be responsive. I do not have sources for either
> > of these applications. Now, reducing the priority of the CPU hogging
> > process does not help much. Normally, the GUI application should only
> > yield the CPU when it doesn't have any more events to process, but
> > since I don't have the sources I can't say for sure.
>
> > Anyhow, I would like to write my own fix for this situation. I was
> > wondering if there is any way to force another process to sleep for a
> > few milliseconds or limit the amount of CPU time it gets. Is such a
> > thing even possible?
>
> > Thanks.
>
> --
> Microsoft Visual C++ MVP
> ========================
> Mi blog sobre programación:http://geeks.ms/blogs/rfog
> Momentos Leves:http://momentosleves.blogspot.com/
> Cosas mías:http://rfog.blogsome.com/
> Libros, ciencia ficción y programación
> ========================================
> Cualquier problema sencillo se puede convertir en insoluble si se celebran
> suficientes reuniones para discutirlo.
> -- Regla de Mitchell.

From: Stefan Kuhr on
Hello Bart,

Bart wrote:
> Hello,
>
> I have an application that is constantly running at 100% CPU and
> causing everything to be sluggish. Another GUI application runs at the
> same time and needs to be responsive. I do not have sources for either
> of these applications. Now, reducing the priority of the CPU hogging
> process does not help much. Normally, the GUI application should only
> yield the CPU when it doesn't have any more events to process, but
> since I don't have the sources I can't say for sure.
>
> Anyhow, I would like to write my own fix for this situation. I was
> wondering if there is any way to force another process to sleep for a
> few milliseconds or limit the amount of CPU time it gets. Is such a
> thing even possible?
>
> Thanks.

Write a program that starts this process and after starting it,
enumerates that processes threads in a loop (using toolhelper API),
while this child process is running. For each enumerated thread, do a
suspend and after a short while a resume. For this to work you have to
open the thread with OpenThread (THREAD_SUSPEND_RESUME) which for this
approach to work has to work across process boundaries (which I never
tried, so this approach may fail).

You might give that a try.

If it is the primary thread of the process that is responsible for the
CPU utilization, things are much easier: You get that thread's handle
via CreateProcess.

--
Stefan
 |  Next  |  Last
Pages: 1 2 3
Prev: Time since wakeup?
Next: Context switch count