1.psutil的安装
1 [root@YQY-TIAN-001 ~]# wget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz 2 [root@YQY-TIAN-001 ~]# tar -xzvf psutil-2.0.0.tar.gz 3 [root@YQY-TIAN-001 ~]# cd psutil-2.0.0 4 [root@YQY-TIAN-001 psutil-2.0.0]# python setup.py install 5 sp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.6 -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-2.6/psutil/_psutil_linux.o 6 unable to execute gcc: No such file or directory 7 error: command 'gcc' failed with exit status 1
发现安装psutil的安装过程中发生了缺少gcc的错误,解决办法如下:
1 yum install gcc python-devel
然后执行下面语句
1 [root@YQY-TIAN-001 psutil-2.0.0]# python setup.py install
相比较而言,使用psutil库实现则更加简单明了。
1 [root@YQY-TIAN-001 psutil-2.0.0]# python 2 Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 3 [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 4 Type "help", "copyright", "credits" or "license" for more information. 5 >>> import psutil 6 >>> mem = psutil.virtual_memory() 7 >>> mem.total,mem.used 8 (1960546304L, 382873600L) 9 >>>