Seite 1 von 1
Reading system resource information
Verfasst: Dienstag 15. Juli 2008, 06:17
von Decepto
Hallo von
Denver. Erbärmlich für aufstellen auf Englisch. Mein Deutsch ist sehr schlecht.
Hi. There is a common Unix program called "
top" that outputs useful system information like "load average", "memory usage", "cpu usage", etc.
I know I can do the following and parse the data within a python script...
Code: Alles auswählen
import os
topData = os.system("top")
# the 'free' command lists free memory
# freeData = os.system("free")
But, I'd rather not rely on the "top" command. Is there a way to view the amount of free memory in a system using pure python?
Verfasst: Dienstag 15. Juli 2008, 07:19
von veers
Hi Decepto,
As you've noticed this is basically a German forum. Anyway... that useful information is located in the /proc folder. Check /proc/uptime, /proc/meminfo and /proc/loadavg. There is a folder for each process in /proc as well. You can find even more information in the /sys folder.
I hope that helps,
- Jonas
Verfasst: Dienstag 15. Juli 2008, 07:26
von BlackJack
For the load average there's `os.getloadavg()` and for the times of the running Python program itself `os.times()`.
For the rest I don't know of a cross platform way, except trying to parse the output of the common tools like `top` and `free`. If you restrict yourself to Linux you maybe can parse `/proc/meminfo` and the `/proc/$PID/` files like `stat`, `statm`, or `status`.
Re: Reading system resource information
Verfasst: Dienstag 15. Juli 2008, 12:55
von lunar
Decepto hat geschrieben:Hallo von
Denver. Erbärmlich für aufstellen auf Englisch. Mein Deutsch ist sehr schlecht.
Doesn't matter ... btw, english support mostly happens in comp.lang.python which is a very active, high quality newsgroup.
But, I'd rather not rely on the "top" command. Is there a way to view the amount of free memory in a system using pure python?
If you're only interested in Linux-compatibility, there's the /proc filesystem (see "man 5 proc"), if unix-compatibility is required, you have to rely on posix commands like "top", since there is no standardized, cross-plattform POSIX API to query system information.
Verfasst: Dienstag 15. Juli 2008, 17:31
von Decepto
Thank you all very very much. That was exactly what I was looking for!
