Linux Shell中PS命令中的%CPU的含义介绍
2009-03-31 15:35
555 查看
PS命令中的%CPU是指一个进程占用CPU的时间百分比,那么具体的含义是什么呢? PS的man手册的解释是这样的:
[/code]
cpu utilization of the process in "##.#" format. Currently, it is the CPU time used divided by the time the process has been running (cputime/realtime ratio),[code]expressed as a percentage. It will not add up to 100% unless you are lucky. (alias pcpu). ps的代码中是这样处理的 :static int pr_pcpu(char *restrict const outbuf, const proc_t *restrict const pp){ unsigned long long total_time; /* jiffies used by this process */ unsigned pcpu = 0; /* scaled %cpu, 999 means 99.9% */ unsigned long long seconds; /* seconds of process life */ total_time = pp->utime + pp->stime; if(include_dead_children) total_time += (pp->cutime + pp->cstime); seconds = seconds_since_boot - pp->start_time / Hertz; if(seconds) pcpu = (total_time * 1000ULL / Hertz) / seconds; if (pcpu > 999U) return snprintf(outbuf, COLWID, "%u", pcpu/10U); return snprintf(outbuf, COLWID, "%u.%u", pcpu/10U, pcpu%10U); }
其中
seconds_since_boot是用当前时间减去系统启动时的时间得到的,启动的时间通过读/proc/stat中的btime获得。而
start_time是进程被fork时设置的。另外进程的时间包括在用户态运行的时间和内核态运行的时间。这样,这个百分比的含义就是从进程被创建到执
行ps操作这段时间T内,这个进程运行的时间和T的比值。
如果在ps中指定了include_dead_children选项,那么这个进程的时间还
包括它的它创建的但已经死去的进程的运行时间,cutime和cstime会在父进程为子进程收尸的时候调用wait_task_zombie来累加。比
如在bash中执行updatedb,在执行完成后,运行 ps -eo pcpu,comm,stat,pid|grep bash 和 ps S -eo pcpu,comm,stat,pid|grep bash
[/code]
相关文章推荐
- ps和top命令的%CPU含义
- ps和top命令的%CPU含义
- Linux Shell命令(1) - chmod/ps/pwd/who
- Linux查看所有进程ps -aux命令介绍
- Linux shell命令示例介绍-个人笔记
- linux shell man命令详细介绍-快捷获得帮助信息(2)
- ps命令中的%CPU字段和top命令中的%CPU字段
- linux之ps命令——进程命令简单介绍
- 解析ANDROID ps命令执行后各项参数的含义
- linux ps top 命令 VSZ,RSS,TTY,STAT, VIRT,RES,SHR,DATA的含义
- 解析ANDROID ps命令执行后各项参数的含义
- linux ps top 命令 VSZ,RSS,TTY,STAT, VIRT,RES,SHR,DATA的含义
- linux系统下的ps命令介绍 查看某个时间点的程序动行情况
- linux ps命令介绍
- free、ps、netstat、tcpdump命令工具介绍
- linux ps 命令的结果中VSZ,RSS,STAT的含义和大小 发表于2013 年 6 月 17 日 ps是linux系统的进程管理工具,相当于windows中的资源管理器的一部分功能。 一般来
- Linux中ps命令介绍
- Android的ps命令介绍和技巧
- linux系统下的ps命令介绍 查看某个时间点的程序动行情况
- ps命令查出来的rss/vsz/size分别是何含义呢