Python shipping Koriyuki Gets the memory information of the operating system

Source: Internet
Author: User

Try this blog, the use of the words will be completely abandoned after the CSDN, change this!


To use Python to get the memory information of the computer needs to use the Psutil module, the memory information that can be obtained is the total amount of memory, the total amount of available memory, the amount of memory used, the percentage of utilization, and other information.

Write a simple little script with the following code:

#!/usr/bin/python

Import Psutil

Pc_mem =psutil.virtual_memory ()

Div_gb_factor = (1024.0 * * 3)

Print ("Totalmemor:%FGB"% float (pc_mem.total/div_gb_factor))

Print ("availablememory:%FGB"% float (pc_mem.available/div_gb_factor))

Print ("usedmemory:%GB"% float (pc_mem.used/div_gb_factor))

Print ("Percentof used memory:%f"% float (pc_mem.percent))

Print ("FREEMEMORY:%FGB"% float (pc_mem.free/div_gb_factor))

The results of the program operation are as follows;

In [1]:%runos_mem.py

Total MEMOR:15.868237GB

Available MEMORY:13.069672GB

Used memory:2.79856b

Percent of usedmemory:17.600000

Freememory:13.069672gb

My computer is equipped with 16G of memory, also does not open how much to eat memory more severe applications. The general situation should be about the same, and there is no need to look at the task Manager to see the specific information.


Python shipping Koriyuki Gets the memory information of the operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.