2

是否有 C/C++ 库以及有关如何在 Solaris 上收集系统和进程信息的文档?

虽然我可以解析命令行工具,但我宁愿使用一个使任务更容易完成的库。

谢谢

编辑:建议使用 /proc 虚拟目录来收集信息,但它并不比解析命令行工具好多少,因为我需要为我的每条数据实现某种自定义解析需要。

我正在寻找类似于 Windows 或 MacOS 的 c 库的东西,它通过基于 c 的系统 API 提供此信息,但是我对谷歌没有运气。

4

5 回答 5

3

You can get this kind of information with kstat API.

man -s 3KSTAT  kstat

You can see how it is used in OpenSolaris vmstat and iostat source.

For information about processus, I'd look at ps.

于 2009-01-15T16:11:21.513 回答
1

Solaris has the /proc virtual directory, which allows you to gather all sorts of information about processes using filesystem I/O functions.

于 2009-01-15T03:01:16.443 回答
1

I would use the /proc virutal dir as CrashWorks has suggested. I've done this on both aux and linux. One thing to keep in mind is when I did use the /proc dir on linux the format of the files varied from one kernel to another.

I don't know what the situation is like on the Solaris side but this could mean that your solution will not be portable from one solaris platform to another.

于 2009-01-15T03:12:47.357 回答
1

what about getrusage()?

于 2009-01-15T03:42:28.887 回答
0

我绝对不是这方面的专家,但我在上学期的一项作业中做了非常相似的事情,当时我们需要对流程进行快照。不幸的是,这种方法需要深入研究内核,这可能不是您想要做的。

我发现这篇文章很有帮助。

无论如何,这里有一些片段。

 write_lock_irq(&tasklist_lock);
  for_each_process(task) {

    if (system_or_user == 0)
      print_mem_user(task);
    if (system_or_user == 1)
      print_mem_system(task);
  }
  write_unlock_irq(&tasklist_lock);

您需要锁定某些数据结构或有时内核会挂起的想法。“for_each_process”是在某处定义的宏,但我不记得它是如何工作的 D:

static void print_mem_system(struct task_struct *task)
{
  struct mm_struct *mm;

  if (task -> mm == NULL){ // this is how you distinguish system processes from user processes
    myarraypid[totalnumberofprocesses] = task -> pid; // store process id's into myarraypid[], which you can later copy back to user space for printing/display. Additional information would be found in a "task_struct" which is Linux's implementation of a process. 



  }


}

我的一些同学采取了不同的方法,并深入研究了“ps”实用程序的源代码。我相信我正在使用 Linux 2.6.18-92.1.13.e15。免责声明:这对我有用,但您的里程可能会有所不同。我很可能会走投无路,我不想把你引向错误的方向。

于 2009-01-15T02:45:23.650 回答