detecting idle processor 
Author Message
 detecting idle processor

How can I use python to detect when the processor is idle? Or when the
network traffic is idle, for a given computer?

I need this to implement a background program.

Thanks in advance,
Sorin Gherman



Fri, 28 Nov 2003 15:00:41 GMT  
 detecting idle processor

Quote:
>How can I use Python to detect when the processor is idle? Or when the network
>traffic is idle, for a given computer?

>I need this to implement a background program.

This is depends very much on the operating system. For the first question
(processor is idle), I think the answer is that you can't do it. All you can do
is run the Python program with a very low priority. This means that it won't
steal much CPU from processes that run at a higher priority. On Unix, you'll
want to use nice for this.

On my Linux system,

nice --adjustment=19 myscript.py

does just that. The parameters of nice would be different on other Unixen, of
course.

Measuring network load is more difficult, but still possible (reading from
/proc on Linux, for example). Which OS do you want to use this on?

Gerhard
--
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://highqualdev.com              public key at homepage
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



Fri, 28 Nov 2003 14:41:57 GMT  
 detecting idle processor

SG> How can I use Python to detect when the processor is idle?

You can't because the processor wouldn't be idle if your Python program is
running. So you first have to define what you mean with "idle".

SG> Or when the network traffic is idle, for a given computer?

That is very much system dependent.

SG> I need this to implement a background program.

The easiest is probably to run your program at a low priority.
--

URL: http://www.cs.uu.nl/~piet [PGP]



Fri, 28 Nov 2003 19:04:17 GMT  
 detecting idle processor

Quote:

> How can I use Python to detect when the processor is idle?

You can run a process with low priority using 'nice', or obtain the
system load by parsing 'uptime'.  But, that's in Unix...

Quote:
> Or when the network traffic is idle, for a given computer?

You can use 'pppstat' for PPP, but I am not sure about ethernet.

Quote:

> I need this to implement a background program.

Easiest solution is 'nice'.

--

8 CPUs cluster, (Slackware) Linux, Python, LaTeX, Vim, Mutt, Sc.



Sat, 29 Nov 2003 03:11:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Processor Idle time

2. How to detect an idle workstation?

3. Detect idle status under a tsr

4. How to detect a Pentium-Processor?

5. Detecting Cyrix, AMD amd PII processors

6. Detecting processor type and speed?

7. Detecting what processor w/o switching modes

8. How to detect Dual Processor.

9. How to detect the processor type....

10. how to detect a processor...

11. How do you detect the processor type ????

12. Idle loops - sometimes a little too idle?

 

 
Powered by phpBB® Forum Software