1
askfermi 2015-08-31 17:57:04 +08:00
ls ('cat >/proc/cpuinfo')
ls ('cat >/proc/meminfo') |
2
maemual 2015-08-31 17:58:08 +08:00
。。。。这个 Google 一下不就有了么。。
psutil |
3
Hakmor OP @askfermi
@maemual 谢谢。附上写好的代码。 ```python #!/usr/bin/env python import time import psutil line_num = 1 def print_line (str ): print str #function of Get CPU State def getCPUstate (interval=1 ): return (" CPU: " + str (psutil.cpu_percent (interval )) + "%") #function of Get Memory def getMemorystate (): phymem = psutil.phymem_usage () buffers = getattr (psutil, 'phymem_buffers', lambda: 0 )() cached = getattr (psutil, 'cached_phymem', lambda: 0 )() used = phymem.total - (phymem.free + buffers + cached ) line = " Memory: %6s" % ( str (int (used / 1024 / 1024 )) + "M", ) return line def poll (interval ): """Retrieve raw stats within an interval window.""" # sleep some time time.sleep (interval ) # get cpu state cpu_state = getCPUstate (interval ) # get memory memory_state = getMemorystate () return (cpu_state,memory_state ) def refresh_window (cpu_state,memory_state ): #print current time #cpu state #memory print_line (time.asctime ()) print_line (cpu_state ) print_line (memory_state ) try: interval =0 while 1: args = poll (interval ) refresh_window (*args ) interval = 1 except (KeyboardInterrupt, SystemExit ): pass ``` |