【问题标题】:How to get information about process in Linux如何在 Linux 中获取有关进程的信息
【发布时间】:2011-04-07 16:34:01
【问题描述】:

如何从内核中获取进程统计信息并返回如下的 buf?

进程数:ticks_user:ticks_system:ticks_interrupt:cpuseconds:procsizes:驻留段大小

我在/proc/[pid]/stat找到了一些资料,但是没有关于ticks system、ticks_interrupt、cpusecond的资料。

我在哪里可以找到有关这些的信息?

任何指向 API 或文档的指针都会有所帮助。

【问题讨论】:

  • 我没有完全理解你的最后一行?你想要一个C程序吗?或者您只是想要文档或信息?
  • 有关滴答系统、滴答中断、cpusecond 的信息或文档。我不知道从哪里获得有关滴答系统、滴答中断、cpusecond 的信息。很抱歉这个错误。
  • 编辑了您的问题。不是问题。只要确保你告诉这里的人你到底想要什么,他们会帮助你的。希望一些 linux 人会来=)

标签: linux process


【解决方案1】:

使用

ps ax
top
htop

首先,阅读手册页,对于 top/htop,按 h 以获得帮助屏幕 q 退出;

但是,没有一个手册页提到蜱 - 它是什么?

【讨论】:

    【解决方案2】:

    你可以试试vmstat。它不是在滴答声中,但为什么需要滴答声?

    CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code. (user time, including nice time)
       sy: Time spent running kernel code. (system time)
       id: Time spent idle. Prior to Linux 2.5.41, this includes I/O-wait time.
       wa: Time spent waiting for I/O. Prior to Linux 2.5.41, included in idle.
       st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
    

    您打算如何处理这些信息?

    有时它也可以通过内核源代码grep,尝试你的流行语。

    【讨论】:

    • 坦克。我正在解析 /proc/[pid]/stat 并找到所需的数据。
    • sscanf(proc_buf, "%*d %*s %*s %*d %*d %*d %*d %*d %*d %*d %*d %*d % *d %d %d %d %*d %*d %*d %*d %d", &cpu_uticks, &cpu_sticks, &cpu_iticks, &i); - proc_buf 是 /proc/[pid]/stat
    • 您可以通过使用regular expression 而不是蛮力 sscanf 来提高代码的可靠性。如果你有可能使用boost 试试看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 2018-02-25
    相关资源
    最近更新 更多