Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?
Alternatively, how could this information be returned on all the above systems with the code specific to that OS being run only if that OS is indeed the operating environment?
os. system only returns the error value.
Regarding cross-platform: your best bet is probably to write platform-specific code, and then import it conditionally. e.g.
import sys if sys.platform == 'win32': import win32_sysinfo as sysinfo elif sys.platform == 'darwin': import mac_sysinfo as sysinfo elif 'linux' in sys.platform: import linux_sysinfo as sysinfo #etc print 'Memory available:', sysinfo.memory_available()
For specific resources, as Anthony points out you can access /proc
under linux. For Windows, you could have a poke around at the Microsoft Script Repository. I'm not sure where to get that kind of information on Macs, but I can think of a great website where you could ask :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With