多核cpu怎样实现让一个cpuio密集型和cpu密集型的程序占用

手机签到经验翻倍!快来扫一扫!
有经验的进来谈谈多核CPU对多任务处理的实际使用情况
3030浏览 / 21回复
双核,三核,四核CPU在多任务处理的情况下,哪个表现的更好,有实际使用经验的来谈谈,不要参考网上的评测,要实际使用经验,比如 几个网游同时运行,同时挂QQ,飞信,MSN,下载,加上网,聊天等等,当然杀毒软件也开着,这个时候不同CPU的不同表现,因为现在发现QQ炫舞双开做任务,挂着QQ,飞信,同时用360浏览器上着网,感觉不是很畅快,CPU占用差不多5,60%& 我配置是X2 3600+ ,780G,4G 667 。准备升级一下,或者换平台,想了解下多核CPU的实际表现怎么样!欢迎有实际使用经验的兄弟来谈谈,谈的好送Z币!
还是要看软件本身的设计,比如maya渲染时候可以把多核心占满。。。我玩的DXM则是3个核眼睁睁的看着一个核累死。。。假设QQ炫舞设计成非焦点状态也占用大量CPU资源,那换4核应该能有些改善,不过这个实际应用我没玩过,能否作为参考楼主自行定夺。
楼主不是妹妹
同意一楼看法
这要看软件在设计的时候有没有这种多核平台
多cpu、多核和单cpu的编程时不一样的
我感觉三核跟双核比效果不是很明显……
声明,文化程度不高。语言组织上不好大家别笑我。
本人97年接触电脑,玩到现在。使用过奔3 奔4 到酷睿双核 四核 目前使用的是 英特尔的至强8核电脑。(不是I7)。 而且我是高专业设计的,在这方面应该有发言权。
首先 在正常任务中 就是正常使用中。 根本感觉不出双核和四核或八核的区别。
先谈下单任务时,单核 双核 四核 八核的区别。
在执行单任务时,还得看那程序是不是支持多核。检查方法同时按键盘上的CTRL+ALT+DEL在进程里 找到你运行的那个程序 右击关系设置。 如果能设置 证明支持。如果不能设置 证明不支持。
不支持的软件 就单软件来说&&核数对软件根本没什么加速效果。
比如用八核玩魔兽争霸之冰封王座(经典游戏,不支持多核),怪多的时候 一样卡机。按CTRL+ALT+DEL发现 CPU使用率 12.5%(8核其中1个CPU满负荷运行,其他几个在睡大觉)
再说下使用支持多核的软件 CPU频率理论可以理解为 单核频X核数。 那么同为2.4G的CPU&&单核是2.4X1=2.4G&&双核是2.4X2=4.8G&&四核是2.4X4=9.6G&& 八核是2.4X8=19.2G&&如果这样的话 速度就一目了然了!
我是做室内设计的,我们渲染效果图的时候 CPU都是满负荷运行。
那么我渲染同1张效果图单核8小时结束的话&&双核就是4小时 四核就是2小时&&8核就是1小时&&正比啊。
再来说下多任务时候的情况!多任务时候 一般CPU都不会满负荷运行。看高清大片,3D游戏。双核绝对够用。除非是专业的用户。 像什么视频编辑,渲染等等。 CPU都是满负荷运行几小时以上的。肯定是核心数越多越好。有点说偏了!多任务时候,运行的软件系统自动平均分配到每个核心上。不但速度提升很多。也减少CPU满负荷的几率。 即使使用专业软件。在执行多任务时候 也可以自己手动设计。 比如我渲染效果图时 8核是每核都是100%的使用率 满负荷了! 我可以同时按CTRL+ALT+DEL ,在进程里找到我的3DMAX软件 右击选择关系设置。 里面弹出0 1 2 。。 7 一共8个核心的CPU控制。默认是打上钩的,就是参与运算。我只需要关闭1个。 那我机器就只有7个核心在运行我的3DMAX渲染效果图。 另1个核 我可以执行其他事情。比如游戏,QQ,电源。爽歪歪。再来说下多任务时候的情况!多任务时候 一般CPU都不会满负荷运行。看高清大片,3D游戏。双核绝对够用。除非是专业的用户。 像什么视频编辑,渲染等等。 CPU都是满负荷运行几小时以上的。肯定是核心数越多越好。有点说偏了!多任务时候,运行的软件系统自动平均分配到每个核心上。不但速度提升很多。也减少CPU满负荷的几率。 即使使用专业软件。在执行多任务时候 也可以自己手动设计。 比如我渲染效果图时 8核是每核都是100%的使用率 满负荷了! 我可以同时按CTRL+ALT+DEL ,在进程里找到我的3DMAX软件 右击选择关系设置。 里面弹出0 1 2 。。 7 一共8个核心的CPU控制。默认是打上钩的,就是参与运算。我只需要关闭1个。 那我机器就只有7个核心在运行我的3DMAX渲染效果图。 另1个核 我可以执行其他事情。比如游戏,QQ,电源。爽歪歪。
就是需要像你这样的经验,谢谢!
难道是一时兴起?这么多字&&&&&&&&&&&&&&&&&&&&&&&&
继续欢迎高手前来指教!
装win7,系统本身就是充分为多核优化过的了。xp里基本现不出什么区别。很多大型软件都对多核尤其是四核优化过,运算更快一些。
没用过多线程的U&&
学习了 差点换双核的去了学习了 差点换双核的去了
对&楼主&舞时舞刻&说:=========================我的是I7 920平台的,系统Vista SP2,最多的记录是同时开了,QQ,讯雷下载,Windows Media Player放音乐,CorelDRAW,PS,ACDSee,3ds Max,但是没有变慢的迹象;
另外,我电脑的开机时间最长是5个白天6个晚上,也没什么性能上的减弱!
我的配置如下:
CPU Intel 酷睿i7 920(盒)
主板 华硕P6T WS Professional(工作站主扳)
内存 金邦2GB DDR3 1600(白金条) X6
硬盘 希捷 1TB M x4&&
显卡 丽台Quadro VX 200(专业图形卡)
机箱 酷冷至尊克斯摩运动版(RC-1100)
电源 ENERMAX 冰核85+ 模块高效850W
对&楼主&舞时舞刻&说:=========================对了!忘记说了一点!
这样下来,我的CPU占用率没超过80%,呵呵
ls的机器超级强,一般人不要跟他比
对&第16楼&lyonbeck&说:=========================抱歉,因为是工作需要啊!呵呵
我单位4核4G内存联想品牌电脑,同时开了N多联想软件
开UT和迅雷一起挂BT,下载上传加起来有十五六个种子吧
开PS,然后最高画质流畅玩使命4
讲下自己的经历,以前处理图形渲染很慢,而且不能去执行别的任务。现在的电脑用的Q9550的U+GTX275
在处理同样的渲染图形时。速度是以前的4倍。当然这也有显卡的因素。另一个简单的例子,WINRAR压缩软件都知道,现在的电脑解压或压缩的速度都是原来的好几倍,速度很快。至于详细应用就更多了。简单总结,至少节约了时间。这年头就时间等不起
8核其中1个CPU满负荷运行,其他几个在睡大觉)
&&这句话比较搞笑
支持键盘翻页 ( 左右 )&
您需要登录后才可以回帖&&&|&&&&&
用户名/注册邮箱/注册手机号
其他第三方号登录多核,如何控制CPU核心
对于多核CPU,如何限制进程在一个CPU上运行呢?
&&&&如何察看某个进程在哪个CPU上运行:
&&&&在控制台中输入:
&&&&之后按下f.进入top
Current Fields设置页面:
&&&&选中:j:
P&&&&&&&&&&=
Last used cpu (SMP)
&&&&则多了一项:P
显示此进程使用哪个CPU。
&&&&经过试验发现:同一个进程,在不同时刻,会使用不同CPU
Core.这应该是Linux Kernel SMP处理的。
本程序通过这个方法查看,将会在多个CPU上运行。
想要让它在一个CPU上执行,可以这样做:
&&&&&&&&&&1.下载包schedtool.
&&&&&&&&&&&&&&&&&&&&在控制台中输入:sudo
apt-get install schedtool,然后输入你的密码。
&&&&schedtool是Linux下用来查询或设置CPU状态的工具。通过不同的参数可以查看或设置不同的属性。
&&&&[-0|-N]
[-1|-F] [-2|-R] [-3|-B] [-4|-I] [-5|-D]
&&&&&&&&&&&&[-M
&&&&&&&&&&&&[-a
&&&&&&&&&&&&[-p
&&&&&&&&&&&&[-n
nice_level]
&&&&&&&&&&&&[-e
command [arg ...]]
&&&&&&&&&&&&[-r]
&&&&&&&&&&&&[-v]
&&&&&&&&&&&&[-h]
&&&&我们这里要用到的是
-a和-e。其他可以参考这里:
&&&&&&&&-a用来设置进程在哪个CPU上运行。-a的参数为:
&&&&&&&&0x1&&表示只运行在CPU0()
&&&&&&&&0x2
表示只运行在CPU1()
&&&&&&&&0x4表示紫云行在CPU2()
&&&&&&&&0x8表示只运行在CPU3()
&&&&&&&&etc.
&&&&&&&&或者,多CPU运行可以这样表示,
&&&&&&&&0x7表示可以运行在CPU0,1,2&&()
&&&&&&&&0x5表示可运行在CPU0,2&&&&&()
&&&&&&&&以此类推。
&&&&&&&&-e用来通过指定的参数来执行命令。后面的参数为控制台命令。
&&&&在Linux下,如何确认是多核或多CPU:
/proc/cpuinfo
&&&&如果有多个类似以下的项目,则为多核或多CPU:
&&&&processor&&&&&&&:
&&&&......
&&&&processor&&&&&&&:
在编译后,我们执行命令:sched -a 0x1 -e
./桌面/sin
可以通过上面介绍的方法查看进程sin是否在同一个CPU上运行。
然后就可以通过系统监视器查看运行结果啦!
运行结果(橙色线):
还有一段Python的代码,运行是与上面类似的,这个来自于网上^_^:
#!/usr/bin/env python import itertools, math, time, sys time_period = float(sys.argv[1]) if len(sys.argv) & 1 else 30 # seconds time_slice = float(sys.argv[2]) if len(sys.argv) & 2 else 0.04 # seconds N = int(time_period / time_slice) for i in itertools.cycle(range(N)): busy_time = time_slice / 2 * (math.sin(2*math.pi*i/N) + 1) t = time.clock() + busy_time while t & time.clock(): pass time.sleep(time_slice - busy_time);
在控制台下输入命令:sched -a 0x1 -e python
./桌面/sin_p.py(此处写你源文件的路径).即可!
1, CPU shield类型(3种)
* root: 包括所有可用CPUS
* system: 包括所有没有屏蔽的cpus
* user: 包括所有已经屏蔽的cpus
2, 查看cpu shield情况
rtdemo:~ # cset shield
cset: **& shielding not active
3, 创建user shield类型cpuset
rtdemo:~ # cset shield
--cpu=1,3,5-7
cset: --& activating
shielding:
cset: moving 132 tasks from root into system
[==================================================]%
cset: "system" cpuset of CPUSPEC(0,2,4) with
132 tasks running
cset: "user" cpuset of CPUSPEC(1,3,5-7) with
0 tasks running
rtdemo:~ # cset shield
cset: --& shielding system
active with
cset: "system" cpuset of CPUSPEC(0,2,4) with
132 tasks running
cset: "user" cpuset of CPUSPEC(1,3,5-7) with
0 tasks running
rtdemo:~ # ps aux | wc -l
4, 查看cpu shield情况
rtdemo:~ # cset shield --verbose
cset: --& shielding system
active with
cset: "system"&n
1.cset&shield -e
--&schedtool&-a
&&性能测试中,启动的程序最好绑定CPU的某个核shield,
&&上面的参数
&&-e&executes
args in the shield
cpuset-name的第几个内核
注意:执行cset之前,先激活CPU内核 :cset shield
--cpu=0,1,2,3
&&&2.&schedtool
-a 0x02 -e command &
cset shield -e --h
Usage: cset shield [options]
[path/program]
&&-c CPUSPEC,
--cpu=CPUSPEC
&&&&&&&&&&&&&&&&&&&&&&&&modifies
or initializes the shield cpusets
--reset&&&&&&&&&&&destroys
the shield
--exec&&&&&&&&&&&&executes
args in the shield
&&--user=USER&&&&&&&&&&&use
this USER for --exec (id or name)
&&--group=GROUP&&&&&&&&&use
this GROUP for --exec (id or name)
--shield&&&&&&&&&&shield
specified PIDSPEC of processes or threads
--unshield&&&&&&&&remove
specified PIDSPEC of processes or threads from
&&&&&&&&&&&&&&&&&&&&&&&&shield
&&-p PIDSPEC,
--pid=PIDSPEC
&&&&&&&&&&&&&&&&&&&&&&&&specify
pid or tid specification for shield/unshield
&&--threads&&&&&&&&&&&&&if
specified, any processes found in the PIDSPEC to
&&&&&&&&&&&&&&&&&&&&&&&&have
multiple threads will automatically have all
&&&&&&&&&&&&&&&&&&&&&&&&their
threads added to the PIDSPEC; use to affect all
&&&&&&&&&&&&&&&&&&&&&&&&related
&&-k on|off,
--kthread=on|off
&&&&&&&&&&&&&&&&&&&&&&&&shield
from unbound interrupt threads as well
--force&&&&&&&&&&&force
operation, use with care
--verbose&&&&&&&&&prints
more detailed output, additive
&&--sysset=SYSSET&&&&&&&optionally
specify system cpuset name
&&--userset=USERSET&&&&&optionally
specify user cpuset name
--help&&&&&&&&&&&&show
this help message and exit
Affinity的设置,到底在系统中会有什么样的积极影响,切换cpu和限制在同一个cpu上到底会让一个进程的效率有什么改变,为此做了一些研究,结论如下:
Cache可以在绑定的情况下,提高命中率。如果一个线程在多个Processor中来回切换,可能会导致CPU的cache持续失效
如果多个线程访问的数据相同,设置同样的Affinity
Mask可以帮助这个Processor提高命中
可以让一些需要高优先级的Process独享一个Processor。通过将系统其他的Process绑定到一个processor上,并将高优先级的Process绑定到空闲的Processor上
对于一个开发者来说,他可以直接使用Linux内核2.5.8版本以后提供的API函数,用来设置自己进程的Affinity
Mask,但是对于系统程序或者不是自己开发的进程怎么办。如果我们不能设置第三方程序的Mask,那么上文的第三点,让某个进程独享一个Processor就无法实现了。
Debian提供了一个工具:schedtool(其他发行版还没有验证),可以使用他来设置一个pid的Affinity
Mask。不过想要把系统所有的进程全部都设置一遍,非常的没有效率。这里有一个简单的办法,因为Affinity
Mask的设置是继承的,子进程会沿用父进程的Mask,我们只需要在系统的启动文件中,将pid为1的系统启动进程设置成我们想要的mask,那么后面的所有系统服务就可以继承这个值了。
修改 /etc/rc.sysinit 在最前方添加
/bin/schedtool -a 0x1 1 /bin/schedtool -a 0x1 $$
这样可以将pid为1和当前的进程的Affinity&Mask设置为1,也就是说只能使用第0号内核。这样,如果假设我们系统有四个核心,我们希望第一个个核心用来跑操作系统自己的相关进程和服务,后面三个核心各跑一个我们自己的服务,就只需要在自己的服务启动之后,再使用bind命令修改他们的Mask即可。
schedtool -h
get/set scheduling policies - v1.3.0, GPL'd, NO WARRANTY
USAGE: schedtool
PIDS&&&&&&&&&&&&&&&&&&&&-
query PIDS
&&&&&&&schedtool
PIDS&&&&&&&&&&-
&&&&&&&schedtool
[OPTIONS] -e
COMMAND&&&&-
exec COMMAND
set scheduling policies:
&&&&-N&&&&&&&&&&&&&&&&&&&&for
SCHED_NORMAL
PRIO&&&&&&&&&&&&for
SCHED_FIFO&&&&&&&only
PRIO&&&&&&&&&&&&for
SCHED_RR&&&&&&&&&only
&&&&-B&&&&&&&&&&&&&&&&&&&&for
SCHED_BATCH
PRIO&&&&&&&&&&&&for
&&&&-D&&&&&&&&&&&&&&&&&&&&for
SCHED_IDLEPRIO
POLICY&&&&&&&&&&&&&for
raw number for POLICY
STATIC_PRIORITY&&&&usually
1-99; only for FIFO or RR
&&&&&&&&&&&&&&&&&&&&&&&&&&higher
numbers means higher priority
NICE_LEVEL&&&&&&&&&set
niceness to NICE_LEVEL
AFFINITY_MASK&&&&&&set
CPU-affinity to bitmask or list
[ARGS]&&&&&start
COMMAND with specified policy/priority
&&&&-r&&&&&&&&&&&&&&&&&&&&display
priority min/max for each policy
&&&&-v&&&&&&&&&&&&&&&&&&&&be
----------------------------------------------------------------------------------------------
3.TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定.
top - 12:38:33 up 50 days,
users,&&load average:
60.58, 61.14, 61.22
Tasks: 203
total,&&60 running, 139
sleeping,&&&4
stopped,&&&0
73.0%sy,&&0.0%ni,&&0.0%id,&&0.0%wa,&&0.0%hi,&&0.0%si,&&0.0%st
Mem:&&&1939780k
total,&&1375280k
used,&&&564500k
free,&&&109680k
Swap:&&4401800k
total,&&&497456k
used,&&3904344k
free,&&&848712k
USER&&&&&&PR&&NI&&VIRT&&RES&&SHR
%MEM&&&&TIME+&&COMMAND&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&627m
11.0 297:14.76
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&626m
R&&&&6&&7.6&&89:16.62
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&672m
R&&&&0&&7.1&&&1283:08
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&672m
R&&&&0&&6.6&&&1272:30
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&672m
R&&&&0&&6.5&&&1270:03
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&672m
R&&&&8&&6.4&&&1274:13
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&672m
R&&&&0&&6.4&&&1279:37
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&634m
R&&&&0&&5.3&&86:13.90
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&632m&&81m&&74m
R&&&&0&&4.3
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&626m&&72m&&71m
R&&&&0&&3.8&&&6:35.68
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&630m&&68m&&63m
R&&&&8&&3.6
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&630m&&66m&&60m
R&&&&0&&3.5
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&630m&&66m&&60m
R&&&&0&&3.5
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&627m&&63m&&63m
R&&&&0&&3.4&&&1:54.93
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&627m&&59m&&58m
R&&&&8&&3.1&&86:09.64
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&627m&&57m&&56m
R&&&&8&&3.0&&84:38.20
oracle&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oracle&&&&25&&&0&&626m&&50m&&49m
R&&&&0&&2.7&&84:55.82
oracle&&&&
一.&&TOP前五行统计信息
统计信息区前五行是系统整体的统计信息。
1. 第一行是任务队列信息
uptime&&命令的执行结果:
[root@localhost ~]# uptime
&13:22:30 up 8
users,&&load average:
0.14, 0.38, 0.25
其内容如下:
&系统运行时间,格式为时:分
&当前登录用户数
load average: 0.06, 0.60, 0.48
&系统负载,即任务队列的平均长度。
三个数值分别为&&1分钟、5分钟、15分钟前到现在的平均值。
2. 第二、三行为进程和CPU的信息
当有多个CPU时,这些内容可能会超过两行。内容如下:
Tasks: 29 total
&正在运行的进程数
28 sleeping
&睡眠的进程数
&停止的进程数
&僵尸进程数
Cpu(s): 0.3% us
&用户空间占用CPU百分比
&内核空间占用CPU百分比
&用户进程空间内改变过优先级的进程占用CPU百分比
&空闲CPU百分比
&等待输入输出的CPU时间百分比
3. 第四五行为内存信息。
内容如下:
Mem: 191272k total
&物理内存总量
173656k used
&使用的物理内存总量
17616k free
&空闲内存总量
22052k buffers
&用作内核缓存的内存量
Swap: 192772k total
&交换区总量
&使用的交换区总量
192772k free
&空闲交换区总量
123988k cached
&缓冲的交换区总量。内存中的内容被换出到交换区,而后又被换入到内存,但使用过的交换区尚未被覆盖,该数值即为这些内容已存在于内存中的交换区的大小。相应的内存再次被换出时可不必再对交换区写入。
二.&&进程信息
&Real user name
&进程所有者的用户id
&进程所有者的用户名
&进程所有者的组名
&启动进程的终端名。不是从终端启动的进程则显示为 ?
&nice值。负值表示高优先级,正值表示低优先级
&最后使用的CPU,仅在多CPU环境下有意义
&上次更新到现在的CPU时间占用百分比
&进程使用的CPU时间总计,单位秒
&进程使用的CPU时间总计,单位1/100秒
&进程使用的物理内存百分比
&进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
&进程使用的虚拟内存中,被换出的大小,单位kb。
&进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
&可执行代码占用的物理内存大小,单位kb
&可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb
&共享内存大小,单位kb
&页面错误次数
&最后一次写入到现在,被修改过的页面数。
&进程状态。
&&&&&&&&&&&&D=不可中断的睡眠状态
&&&&&&&&&&&&R=运行
&&&&&&&&&&&&S=睡眠
&&&&&&&&&&&&T=跟踪/停止
&&&&&&&&&&&&Z=僵尸进程
&命令名/命令行
&若该进程在睡眠,则显示睡眠中的系统函数名
&任务标志,参考 sched.h
top 的man 命令解释如下:
&&&&Listed
below are top's available
fields.&&They are always
associated with
the&&letter&&shown,&regardless&&of
the position you may have established for them with the 'o' (Order
fields) interactive command.Any field is selectable as the sort
field, and you control whether they
are&sorted
high-to-low&&or&&low-to-high.&&&For&&additional&&information
on sort provisions
see&&topic 3c. TASK Area
PID&&--&&Process
&&&&&&&The
task's unique process ID, which periodically wraps, though
never&&restarting at
PPID&&--&&Parent
Process Pid
&&&&&&&The
process ID of a task's parent.
RUSER&&--&&Real
&&&&&&&The
real user name of the task's owner.
UID&&--&&User
&&&&&&&The
effective user ID of the task's owner.
USER&&--&&User
&&&&&&&The
effective user name of the task's owner.
GROUP&&--&&Group
&&&&&&&The
effective group name of the task's owner.
TTY&&--&&Controlling
&&&&&&&The&&name
of the controlling
terminal.&&This is usually
the device (serial port, pty, etc.) from which the process was
started, and which it
uses&&for&&input&&oroutput.&&&However,&&a
task need not be associated with a terminal, in which case you'll
see '?' displayed.
PR&&--&&Priority
&&&&&&&The
priority of the task.
NI&&--&&Nice
&&&&&&&The
nice value of the
task.&&&A&&negative&&nice&&value&&means&&higher&&priority,
whereas&a&&positive
nice value means lower
priority.&&Zero in this
field simply means priority will not be adjusted in determining a
task's dispatchability.
P&&--&&Last
used CPU (SMP)
number representing the last used
processor.&&In a true
SMP&&environment&&this
will likely change frequently since the kernel intentionally uses
weak affinity. Also, the very act of running top may break this
affinity&&and&&cause&&more
processes&&to change CPUs
more often (because of the extra demand for cpu time).
%CPU&&--&&CPU
&&&&&&&The
task's share of the elapsed CPU time since the last screen update,
expressed as a percentage of total CPU
time.&&In a true SMP
environment, if 'Irix mode' is Off, top will operate in 'Solaris
mode' where a task's cpu usage will be divided
by&&the&&total&&number&&of&&CPUs.&&&You
toggle 'Irix/Solaris' modes with the 'I' interactive
TIME&&--&&CPU
&&&&&&&Total
CPU time the task has used since it
started.&&When&&'Cumulative&&mode'&&is
On,&&each&process
is listed with the cpu time that it and its dead children has
used.&&You toggle
'Cumulative mode' with 'S', which is a command-line option and an
interactive command.&&See
the 'S' interactive command for additional information regarding
this mode.
TIME+&&--&&CPU
Time, hundredths
&&&&&&&The
same as 'TIME', but reflecting more granularity through hundredths
sec&&&&&&&&&ond.
%MEM&&--&&Memory
usage (RES)
task's currently used share of available physical
VIRT&&--&&Virtual
Image (kb)
&&&&&&&The
total amount of virtual memory used by the
task.&&It includes all
code, data and shared libraries plus pages that
have&&been&&swapped&&out.&&(Note:&&you&&can
define&&the STATSIZE=1
environment variable and the VIRT will be calculated from the
/proc/#/state VmSize field.)
&&&&&&&VIRT
= SWAP + RES.
SWAP&&--&&Swapped
&&&&&&&The
swapped out portion of a task's total virtual memory
RES&&--&&Resident
&&&&&&&The
non-swapped physical memory a task has used.
&&&&&&&RES
= CODE + DATA.
CODE&&--&&Code
&&&&&&&The
amount of physical memory devoted to
executable&&code,&&also&&known&&as&&the'text
resident set' size or TRS.
DATA&&--&&Data+Stack
&&&&&&&The&&amount
of physical memory devoted to other than executable code, also
known the 'data resident set' size or DRS.
SHR&&--&&Shared
Mem size (kb)
&&&&&&&The
amount of shared memory used by a
task.&&&It&&simply&&reflects&&memory&&that
could be potentially shared with other processes.
nFLT&&--&&Page
Fault count
&&&&&&&The&&number&&of&&major&&page
faults that have occurred for a
task.&&A page fault occurs
when a process attempts to read from or write to a virtual
page&&that&&is
not&&currently&&present&in&&its
address space.&&A major
page fault is when disk access is involved in making that page
available.
nDRT&&--&&Dirty
Pages count
&&&&&&&The
number of pages that have been modified
since&&they&&were&&last&&written&&to
disk.&&Dirty&&pages&&must&&be
written to disk before the corresponding physical memory location
can be used for some other virtual page.
S&&--&&Process
&&&&&&&The
status of the task which can be one of:
&&&&&&&&&&&&&'D'
= uninterruptible sleep
&&&&&&&&&&&&&'R'
&&&&&&&&&&&&&'S'
= sleeping
&&&&&&&&&&&&&'T'
= traced or stopped
&&&&&&&&&&&&&'Z'
&&&&&&&Tasks
shown as running should be more properly thought of as 'ready to
run'&&--their&task_struct
is simply represented on the Linux
run-queue.&&Even without a
true SMP machine, you may see numerous tasks in this
state&&depending&&on&&top's
delay interval and nice value.
Command&&--&&Command
line or Program name
&&&&&&&Display
the command line used to start a task or the name of the associated
program.&&You toggle
between command line and name with 'c', which is
both&&a&&command-line
option and an interactive command.
When&&you've&&chosen&&to
display command lines, processes without a command line (like
kernel threads) will be shown with only the program
name&&in&&parentheses,
as in this
example:&&&&&&&&&&&&&&&&(
mdrecoveryd )
Either&&form&&of&&display
is subject to potential truncation if it's too long to fit in this
field's&&current&&width.&&&That&&width&&depends&&upon&other&&fields&&selected,
their order and the current screen width.
&&&&&&&Note:
The 'Command' field/column is unique, in that it is not
fixed-width.&&When
displayed, this column will be allocated all remaining screen width
(up&&to&&the
maximum&&512&&characters)&to&&provide
for the potential growth of program names into command
WCHAN&&--&&Sleeping
in Function
&&&&&&&Depending
on the availability of the kernel link map ('System.map'),
this&&field
will&show&&the&&name
or the address of the kernel function in which the task is
currently sleeping.&Running tasks will
display a dash ('-') in this column.
&&&&&&&Note:
By displaying this field, top's own working set will be increased
700Kb.&&Your&&only&&means
of reducing that overhead will be to stop and
restart&&&&&&&&&&top.
Flags&&--&&Task
&&&&&&&This
column represents the task's current scheduling flags
which&&are&&expressed
in&hexadecimal&&notation
and with zeros
suppressed.&&These flags
are officially documented in
.&&Less formal
documentation can also
be&&found&&on
the 'Fields select' and 'Order fields' screens.
&&&&&&&默认情况下仅显示比较重要的&&PID、USER、PR、NI、VIRT、RES、SHR、S、%CPU、%MEM、TIME+、COMMAND&&列。
2.1 用快捷键更改显示内容。
(1)更改显示内容通过 f键可以选择显示的内容。
f 键之后会显示列的列表,按
a-z&&即可显示或隐藏对应的列,最后按回车键确定。
(2)按o键可以改变列的显示顺序。
&&&&&&&按小写的
a-z 可以将相应的列向右移动,而大写的
A-Z&&可以将相应的列向左移动。最后按回车键确定。
&&&&&&&按大写的
F 或 O 键,然后按 a-z
可以将进程按照相应的列进行排序。而大写的&&R
键可以将当前的排序倒转。
&&&&&&&设置完按回车返回界面。
进程top -c -d 5
&/tmp/cpu.txt&&&&<img NAME="image_operate_01747" ALT="linux&&wbr&top&&wbr&&&&wbr&cset&schedtool对于多核CPU,如何限制进程在一个CPU上运行" TITLE="linux&&wbr&top&&wbr&&&&wbr&cset&schedtool对于多核CPU,如何限制进程在一个CPU上运行" STYLE="margin: 0 padding: 0 list-style:" />&每5s显示一下内存信息
grep -i 进程名 /tmp/cpu.txt |
/tmp/cpu-01.txt&&查找相关进程的CPU内存使用到一个文件
三.&&命令使用
详细内容可以参考MAN 帮助文档。这里列举部分内容:
命令格式:
top [-] [d] [p] [q] [c] [C]
[S]&&&&[n]
参数说明:
d:&&指定每两次屏幕信息刷新之间的时间间隔。当然用户可以使用s交互命令来改变之。
p:&&通过指定监控进程ID来仅仅监控某个进程的状态。
q:该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行。
S: 指定累计模式
使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险。
i:&&使top不显示任何闲置或者僵死进程。
c:&&显示整个命令行而不只是显示命令名
在top命令的显示窗口,我们还可以输入以下字母,进行一些交互:
帮助文档如下:
Help for Interactive Commands - procps
version 3.2.7
Window 1:Def: Cumulative mode
Off.&&System: Delay 4.0
Secure mode Off.
&&Z,B&&&&&&&Global:
'Z' c 'B' disable/enable bold
&&l,t,m&&&&&Toggle
Summaries: 'l' 't' task/ 'm' mem
&&1,I&&&&&&&Toggle
SMP view: '1' single/ 'I' Irix/Solaris
&&f,o&&&&&.
Fields/Columns: 'f' 'o' change display
or O&&. Select sort
&&&,&&&&&&.
Move sort field: '&'
'&' next col right
&&R,H&&&&&.
Toggle: 'R' normal/ 'H' show threads
&&c,i,S&&&.
Toggle: 'c' cmd name/ 'i' 'S' cumulative
&&x,y&&&&&.
Toggle highlights: 'x' 'y' running tasks
&&z,b&&&&&.
Toggle: 'z' color/ 'b' bold/reverse (only if 'x' or
&&u&&&&&&&.
Show specific user only
or #&&. Set maximum tasks
&&k,r&&&&&&&Manipulate
tasks: 'k' 'r' renice
update interval
&&W&&&&&&&&&Write
configuration file
&&q&&&&&&&&&Quit
&&&&&&&&&&(
commands shown with '.' require a visible task display window
Press 'h' or '?' for help with
显示帮助画面,给出一些简短的命令总结说明。
k&&:终止一个进程。系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。一般的终止进程可以使用15信号;如果不能正常结束那就使用信号9强制结束该进程。默认值是信号15。在安全模式中此命令被屏蔽。
i:忽略闲置和僵死进程。这是一个开关式命令。
q:&&退出程序。
r:&&重新安排一个进程的优先级别。系统提示用户输入需要改变的进程PID以及需要设置的进程优先级值。输入一个正值将使优先级降低,反之则可以使该进程拥有更高的优先权。默认值是10。
S:切换到累计模式。
:&&改变两次刷新之间的延迟时间。系统将提示用户输入新的时间,单位为s。如果有小数,就换算成ms。输入0值则系统将不断刷新,默认值是5
s。需要注意的是如果设置太小的时间,很可能会引起不断刷新,从而根本来不及看清显示的情况,而且系统负载也会大大增加。
f或者F :从当前显示中添加或者删除项目。
o或者O&&:改变显示项目的顺序。
l: 切换显示平均负载和启动时间信息。即显示影藏第一行
m: 切换显示内存信息。即显示影藏内存行
t : 切换显示进程和CPU状态信息。即显示影藏CPU行
c:&&切换显示命令名称和完整命令行。
显示完整的命令。 这个功能很有用。
M : 根据驻留内存大小进行排序。
P:根据CPU使用百分比大小进行排序。
T: 根据时间/累计时间进行排序。
W:&&将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。
详细出处参考:
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 cpu密集型应用有哪些 的文章

 

随机推荐