views:

335

answers:

5

I've written an image processing script in php which is run as a cron scheduled task (in OSX). To avoid overloading the system, the script checks the system load (using 'uptime') and only runs when load is below a predefined threshold.

I've now ported this over to Windows (2003 Server) and am looking for a similar command line function to report system load as an integer or float.

A: 

You can use a command-line utility called pv to display the process name and CPU% usage over a specific time period (defaults to 500ms) using this command line:

pve.exe -o"%n\t%c"

There is help using the -? switch that describes the available parameters.

It will require a little more work than uptime on OSX/linux, since you would have to total the numbers from the first column (or omit the process name and simply total the value form each line of output) to get the total (in %) CPU usage.

The up side is that with a little more work, you could get the specific amount of CPU that your executing process is using, rather than overall system CPU consumption.

ringmaster
A: 

WMI benchmarks pretty much everything in Windows, including system load.

I found a thread about it.

Edouard A.
+1  A: 

You can try this at a windows command line. This works in XP, get a lot of other info too.

wmic CPU

OIS
A: 

Just use standard win32 apis (GTC)

+2  A: 

Don't use load...

The system load is not a good indicator in this case. On Unix it essentially tells you, how many processes are ready and waiting to be executed at the moment. But since there are numerous reasons for why a process might have to wait, your script may actually be able to run without costing another process any performance, even if the "load" on the system is high.

... use nice

You should use nice(1) on Unix and the equivalent on Windows ("Process Priority"?), so the OS can decide, when to run your script!

If you set the priority of your script to the absolute lowest possible priority then it will only be executed by the scheduler when there is nothing else to do at the moment.

Probably you will have to implement some kind of mechanism to prevent more than one instance of your script to be run at the same time, in case it takes longer to execute than the interval between to invocations lasts.

hop