gpt4 book ai didi

linux - 我如何获取信息/proc/$pid/smaps

转载 作者:太空宇宙 更新时间:2023-11-04 11:19:00 24 4
gpt4 key购买 nike

我必须制作一个 bash 脚本来启动 /proc/$pid/smaps 以下信息,而不是:

total memory: 2mb

Memory resident: 3kb

private memory + shared: 3kb

Private total memory: 5kb

如何访问数据并添加行列?如果我执行 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 从第二行打印到文件末尾(=忽略第一行):

tail +2 /path/to/proc

我希望这能满足您的需求。

关于linux - 我如何获取信息/proc/$pid/smaps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19446002/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com