Python Script 9: Getting System Information in Linux using python script

Finding system information in Ubuntu like Number and type of processors, memory usage, uptime etc are extremely easy. You can use Linux system commands like  free -m  ,  uname -a  and  uptime  to find these details.

But there is no fun in doing that. If you love coding in python, you want to do everything in python. So we will see how to find this information using python program. And in the process will learn something about Linux system in addition to python.

To find few details we will use python module, platform. We will be running this script using python3 interpreter and this script is tested on Ubuntu 16.04.

General Info:

So platform module is used to Access the underlying platform’s identifying data. We will be using some of the method available in this module.

To get Architecture, call architecture method. It return a tuple (bits, linkage).  platform.architecture() .

To get the Linux distribution, call  dist()  or  linux_distribution()  method. It also returns a tuple.

Now to get other information we need to go into  /proc/  directory of your system. If you look at files you will get an idea where system stores this type of information.

Processor Info:

Processor information is stored in cpuinfo file. Read the file and count the number and model name of processor.

Memory Usage:

Memory details are stored in  /proc/meminfo  file. First line is the Total memory in system and second line is the free memory available at the moment.


How long your system has been up.

Average Load:


Complete code is available on Github.

Run the script :  python3


Linux system information using python script

Host your Django App for free on PythonAnyWhere Server.

(Visited 349 times, 1 visits today)

You must read this :

Leave a Reply

Your email address will not be published. Required fields are marked *