我必须制作一个bash脚本,它将/proc/$pid/smaps
踢出以下信息,而不是:
total memory: 2mb
Memory resident: 3kb
private memory + shared: 3kb
Private total memory: 5kb
如何访问数据并添加cantiades?
如果我做一个
cat / proc / $ pid / smaps
给我所有的行文件,不知道如何选择只有那些你想要的。 最佳答案
您可以使用grep
获取具有模式匹配的特定行,例如:
grep -e ^Private -e ^Rss -e ^Pss /path/to/proc
一种同等的、较短但不易携带的方式:
grep -E '^(Private|Rss|Pss)' /path/to/proc
您可以使用
sed
按行号打印特定行:# print 5th line
sed -ne 5p
# print from 5th line until the end of file
sed -ne '5,$p'
# print everything except the 5th line (= delete the 5th line)
sed -e 5d
您可以使用
tail
从第2行打印到文件结尾(=忽略第一行):tail +2 /path/to/proc
我希望这能满足你的需要。
关于linux - 我如何获取信息/proc/$ pid/smaps,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19446002/