Discussion:
CPU Usage Limit
(too old to reply)
Manish
2008-06-11 04:32:13 UTC
Permalink
Hi, I am new to win32 programming.
I want to create an application in such a way that we can limit the
usage of CPU by this process. Say 50 or 60%.
If the CPU usage by this process is going to be increased more than 60
% then the application should sleep.
There are some API through which i can find the cpu usage .....
Is there any direct API which will limit the CPU usage by a particular
process???
Christian ASTOR
2008-06-11 06:04:40 UTC
Permalink
Post by Manish
Hi, I am new to win32 programming.
I want to create an application in such a way that we can limit the
usage of CPU by this process. Say 50 or 60%.
If the CPU usage by this process is going to be increased more than 60
% then the application should sleep.
There are some API through which i can find the cpu usage .....
Is there any direct API which will limit the CPU usage by a particular
process???
e.g. with SuspendThread()-ResumeThread()
(you can see BES (Battle Encoder Shirase) source code)
Manish
2008-06-11 06:10:02 UTC
Permalink
Post by Christian ASTOR
Post by Manish
Hi, I am new to win32 programming.
I want to create an application in such a way that we can limit the
usage of CPU by this process. Say 50 or 60%.
If the CPU usage by this process is going to be increased more than 60
% then the application should sleep.
There are some API through which i can find the cpu usage .....
Is there any direct API which will limit the CPU usage by a particular
process???
e.g. with SuspendThread()-ResumeThread()
(you can see BES (Battle Encoder Shirase) source code)
Hi, thanksa for reply....But the problem is how to find out whether
the CPU usage by my process is 50% or not??
Is there any API by which i can directly set the CPU usage maximum
bound of my process
unknown
2008-06-11 08:43:40 UTC
Permalink
Post by Manish
Post by Christian ASTOR
Post by Manish
Hi, I am new to win32 programming.
I want to create an application in such a way that we can limit the
usage of CPU by this process. Say 50 or 60%.
If the CPU usage by this process is going to be increased more than
60 % then the application should sleep.
There are some API through which i can find the cpu usage .....
Is there any direct API which will limit the CPU usage by a
particular process???
e.g. with SuspendThread()-ResumeThread()
(you can see BES (Battle Encoder Shirase) source code)
Hi, thanksa for reply....But the problem is how to find out whether
the CPU usage by my process is 50% or not??
Is there any API by which i can directly set the CPU usage maximum
bound of my process
Why? Why not set the thread priority to below normal, or low? That'll
allow your App to run, but if some other program needs the CPU then
they'll get it.

Puckdropper
--
If you're quiet, your teeth never touch your ankles.

To email me directly, send a message to puckdropper (at) fastmail.fm
Jerry Coffin
2008-06-11 15:28:59 UTC
Permalink
In article <cdc9c95b-75bf-4ec1-ba5f-
***@n19g2000prg.googlegroups.com>, ***@gmail.com
says...

[ ... ]
Post by Manish
Hi, thanksa for reply....But the problem is how to find out whether
the CPU usage by my process is 50% or not??
Is there any API by which i can directly set the CPU usage maximum
bound of my process
AFAIK, there's no way to set it directly for a process. A job object
will allow you to set a total CPU usage limit for a job (which can
include an arbitrary number of processes).

You can compute your process' CPU usage by calling GetProcessTimes at
intervals, and comparing the change in user and kernel time to the
change in wall time.
--
Later,
Jerry.

The universe is a figment of its own imagination.
Manish
2008-06-18 11:57:40 UTC
Permalink
Post by Jerry Coffin
In article <cdc9c95b-75bf-4ec1-ba5f-
says...
[ ... ]
Post by Manish
Hi, thanksa for reply....But the problem is how to find out whether
theCPUusageby my process is 50% or not??
Is there any API by which i can directly set theCPUusagemaximum
bound of my process
AFAIK, there's no way to set it directly for a process. A job object
will allow you to set a totalCPUusagelimit for a job (which can
include an arbitrary number of processes).
You can compute your process'CPUusageby calling GetProcessTimes at
intervals, and comparing the change in user and kernel time to the
change in wall time.
--
    Later,
    Jerry.
The universe is a figment of its own imagination.
you mean to say we can limit the cpu usage of task but not the
process.
i had implemented the 2nd idea which you have mentioned .but it
requires continues processing to check the currently usage of cpu by
my process
Jerry Coffin
2008-06-18 18:17:32 UTC
Permalink
In article <ce326c93-9181-4f29-b22c-
***@g16g2000pri.googlegroups.com>, ***@gmail.com
says...
[ ... ]
Post by Manish
Post by Jerry Coffin
AFAIK, there's no way to set it directly for a process. A job object
will allow you to set a totalCPUusagelimit for a job (which can
include an arbitrary number of processes).
[ ... ]
Post by Manish
you mean to say we can limit the cpu usage of task but not the
process.
Job, not task. You can limit the _total_ amount of CPU time used for the
job, but not the percentage at any given time. E.g. if you set a limit
of 5 seconds of CPU time, it could use 100% of the CPU for 5 seconds, or
50% for 10 seconds, or 20% for 25 seconds, but the overall total won't
exceed 5 seconds.
Post by Manish
i had implemented the 2nd idea which you have mentioned .but it
requires continues processing to check the currently usage of cpu by
my process
Surely -- though it certainly doesn't involve _much_ processing.
--
Later,
Jerry.

The universe is a figment of its own imagination.
Loading...