运行 top,打印输出,然后退出或者如何在没有 top 的情况下获取实际内存使用情况

发布于 2024-08-23 03:06:00 字数 192 浏览 5 评论 0原文

我运行的是 Mac OS 10.6。我想运行 top 来获取内存使用情况,但不是在交互模式或任何更新模式下。我只想知道当时的内存使用情况,然后返回提示。我已经寻找其他实用程序来获取内存使用情况...但结果很差(vm_stat 用于虚拟内存)。有人可以指导我如何获取 top 或其他东西来将内存使用情况打印到标准输出吗?

I'm running Mac OS 10.6. I want to run top to get memory usage, but not in interactive mode, or any mode that updates. I just want memory usage at that point in time then return to prompt. I've looked for other utilities to get memory usage... but came up short (vm_stat is for virtual memory). Can someone direct me how to get top or something else to print memory usage to stdout?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初雪 2024-08-30 03:06:00

top -l 1 只会将一个样本放入标准输出(当然,您可以根据需要重定向它、过滤它等)。 man top 了解更多详细信息。

top -l 1 will put just one sample to standard output (you can redirect it, filter it, etc, as you wish of course). man top for many more details.

稍尽春風 2024-08-30 03:06:00

您还可以使用ps命令。例如,

ps -eo pmem,comm

查看 ps 手册页以获取更多输出格式。例如 RSS、大小等。

you can also use the ps command. eg

ps -eo pmem,comm

check the ps man page for more output formatting. eg rss, size etc..

享受孤独 2024-08-30 03:06:00

我一直在使用这个命令在前几行中吐出基本信息

top -l 1 -n 0

-l 1 = 只是一个样本
-n 0 = 0 处理

这有点黑客……但如果你只想要内存行……你可以通过头部和尾部来提供它。

top -l 1 -n 0 | head -n 5 | tail -n 2

I've been using this command to spit out the basic info in the first few lines

top -l 1 -n 0

-l 1 = just one sample
-n 0 = 0 processes

this is a bit of a hack .... but if you only want the memory line ... you could feed it through head and tail.

top -l 1 -n 0 | head -n 5 | tail -n 2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文