File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,33 @@ class PROCESS_MEMORY_COUNTERS_EX(ctypes.Structure):
34
34
return 0
35
35
return mem_struct .PrivateUsage
36
36
37
+ elif sys .platform == 'linux2' :
38
+ import os
39
+
40
+ _scale = {'kb' : 1024 , 'mb' : 1024 * 1024 }
41
+
42
+ def _VmB (key ):
43
+ """Read the /proc/PID/status file to find memory use."""
44
+ try :
45
+ # get pseudo file /proc/<pid>/status
46
+ t = open ('/proc/%d/status' % os .getpid ())
47
+ v = t .read ()
48
+ t .close ()
49
+ except IOError :
50
+ return 0 # non-Linux?
51
+ # get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
52
+ i = v .index (key )
53
+ v = v [i :].split (None , 3 )
54
+ if len (v ) < 3 :
55
+ return 0 # invalid format?
56
+ # convert Vm value to bytes
57
+ return int (float (v [1 ]) * _scale [v [2 ].lower ()])
58
+
59
+ def process_ram ():
60
+ """How much RAM is this process using? (Linux implementation"""
61
+ return _VmB ('VmRSS' )
62
+
63
+
37
64
else :
38
65
def process_ram ():
39
66
"""How much RAM is this process using? (no implementation)"""
You can’t perform that action at this time.
0 commit comments