擅长:python、mysql、java
<p>大概是这样的:</p>
<pre><code>desiredTags = [ 'MemTotal', 'MemFree', 'Cached', 'SwapCached', 'SwapTotal',
'SwapFree', 'AnonPages', 'Dirty', 'Writeback', 'PageTables',
'HugePages_Total', 'HugePages_Free', 'HugePages_Rsvd',
'HugePages_Surp' ]
stats = []
with open('/proc/meminfo') as fd:
for line in fd:
fields = line.strip().split()
# strip off the colon from the first field
if fields[0][:-1] in desiredTags:
stats.append(fields[1])
print ' '.join(stats)
</code></pre>
<p>我不确定我得到了理想的标签清单完全正确-请随时修改这些必要的。你知道吗</p>