c - 确定 CPU 利用率 - Solaris unix

标签 c unix process solaris

我刚刚经历过SO,发现了一个问题Determining CPU utilization

这个问题很有趣,更有趣的是答案。 所以我想对我的 Solaris SPARC unix 系统进行一些检查。

我以 root 用户身份进入/proc,发现了一些名称为数字的目录。 我认为这些数字是进程 ID。令人惊讶的是我没有找到/stat。(不知道为什么?..)

我获取了一个进程 ID(一个目录)并检查了其中的内容。下面是输出

root@tiger> cd 11770
root@tiger> pwd
/proc/11770
root@tiger> ls
as         contracts  ctl        fd         lstatus    lwp        object     path       psinfo     root       status     watch
auxv       cred       cwd        lpsinfo    lusage     map        pagedata   priv       rmap       sigact     usage      xmap

我确实检查了这些文件是什么:

root@tigris> file *
as:             empty file
auxv:           data
contracts:      directory
cred:           data
ctl:            cannot read: Invalid argument
cwd:            directory
fd:             directory
lpsinfo:        data
lstatus:        data
lusage:         data
lwp:            directory
map:            TrueType font file version 1.0 (TTF)
object:         directory
pagedata:       cannot read: Arg list too long
path:           directory
priv:           data
psinfo:         data
rmap:           TrueType font file version 1.0 (TTF)
root:           directory
sigact:         ascii text
status:         data
usage:          data
watch:          empty file
xmap:           TrueType font file version 1.0 (TTF)

我不确定..鉴于此我如何确定CPU利用率? 例如:我的进程的空闲时间是多少。

谁能给我正确的方向吗? 可能有一个例子!

最佳答案

由于没有其他人上钩,我将添加一些评论/答案。

第一,您检查过 Solaris System tuning 的可用信息吗? ?这是针对旧版 Solarian、2.6、v7 和 8 的。大概在developers.sun.com 上稍微搜索一下就会发现更新的内容。

你写道:

I went to /proc as root user and i found out some directories with numbers as their names. I think these numbers are the process id's.Surprisingly i did not find /stat.(donno why?..)

许多非 Linux 操作系统对于如何管理进程都有自己的特殊约定。 对于 Solaris,/proc 目录不是基于磁盘的文件目录,而是有关所有事件系统进程的信息,这些进程像目录层次结构一样排列。很酷,对吧?

我不知道stat的具体含义,status?统计数据?还有别的东西吗?但这只是使用不同操作系统的目录结构来保存进程信息的约定。

正如您所发现的,/proc/ 下面是一堆编号的条目,这些是事件的 processID。当您进入其中任何一个时,您就会看到可用于该进程的系统信息。

I did check what are those files : ....

我无法再访问 Solaris 服务器,因此我们必须进行一些猜测。我建议“深入”到名称暗示任何相关内容的任何文件或目录。

您尝试过cat psinfo吗?那产生了什么?

如果 Solaris 调整页面没有帮助,那么您的 appropos 是否正常工作?执行appropos proc 并查看提到了哪些手册页。深入研究这些。或者尝试 man proc,然后查看条目底部附近的“另请参阅”部分和示例部分。

(Un)?幸运的是,大多数手册页都不是教程,因此通读这些手册可能只会让您了解还需要学习多少内容。


您知道提供一些性能监控功能的内置命令,例如 pstop 等?

优秀的基于 AIX 的 nmon 已经/正在存在?也移植到 Solaris,请参阅 http://sourceforge.net/projects/sarmon/

还有网络管理员喜欢拥有的昂贵的监控/测量/利用工具,作为一个纯粹的开发人员,我们从来没有使用过它们。当您在 Google 上搜索“Solaris 性能监控”时,请查看付费广告。

最后,请记住 FAQ for nmon 中包含的 nmon-AIX 系统监视器的开发人员的这一出色观察。 :

If you keep using shorter and shorter periods you will eventually see that the CPUs are either 100% busy or 100% idle all the other numbers are just a feature of humans not thinking fast enough and having to average out the CPU use in longer periods.

我希望这会有所帮助。

关于c - 确定 CPU 利用率 - Solaris unix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9158551/

相关文章:

c - atoi 从定义的索引将字符串转换为 char

c - 处理管道、 fork 时的救助策略

python - 在 Windows 上构建 64 位 C Python 扩展

linux - 从 shell 脚本内部记录 sql 错误

c++ - 如何使用管道同步父进程和子进程?

java - 启动 DLL 进程不工作

c - 扫描两个不同的字符,以及整数,需要一次全部打印

linux - Linux Shell 脚本中的动态注释更改

regex - 在 sed 模式中指定 "-"

c++ - 如何让两个子进程互相等待