ps查看和调整优先级
主题ps查看和调整优先级
一查看优先级
nice值越大优先级越低
[root@centos72 ~]# ps axo pid,cmd,ni | head
PID CMD NI
1 /usr/lib/systemd/systemd -- 0
2 [kthreadd] 0
3 [ksoftirqd/0] 0
5 [kworker/0:0H] -20
7 [migration/0] -
8 [rcu_bh] 0
9 [rcu_sched] 0
10 [lru-add-drain] -20
11 [watchdog/0] -
[root@centos72 ~]# ps axo pid,cmd,ni | tail
8406 [kworker/1:1] 0
8457 sshd: root@pts/3 0
8465 -bash 0
8485 dd if=/dev/zero of=/dev/nul 0
8573 [kworker/1:1H] -20
10541 [kworker/0:2] 0
11025 [kworker/0:1] 0
11295 [kworker/0:0] 0
11297 ps axo pid,cmd,ni 0
11298 tail
开启一个进程
[root@centos72 ~]# ping -f 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
^C
--- 127.0.0.1 ping statistics ---
4860967 packets transmitted, 4860967 received, 0% packet loss, time 44792ms
rtt min/avg/max/mdev = 0.001/0.003/14.741/0.028 ms, pipe 2, ipg/ewma 0.009/0.009 ms
按照CPU进行排序,CPU占用过高
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu k %cpu | tail
1142 -bash 0 0.0
1230 [kworker/0:1] 0 0.0
1253 [kworker/0:2] 0 0.0
1255 sshd: root@pts/1 0 0.0
1259 -bash 0 0.0
1338 ps axo pid,cmd,ni,%cpu k %c 0 0.0
1339 tail 0 0.0
1294 [kworker/0:0] 0 0.1
906 sshd: root@pts/0 0 0.2
1283 ping -f 127.0.0.1 0 95.9
二调整优先级
注意此时进程正在运行
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu k %cpu | grep ping
1355 grep --color=auto ping 0 0.0
1283 ping -f 127.0.0.1 0 96.0
[root@centos72 ~]# renice -n -20 1283
1283 (process ID) old priority 0, new priority -20
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu k %cpu | grep ping
1358 grep --color=auto ping 0 0.0
1283 ping -f 127.0.0.1 -20 95.8
注意此时进程正在运行
[root@centos72 ~]# ping -f 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
.^
--- 127.0.0.1 ping statistics ---
7827881 packets transmitted, 7827881 received, 0% packet loss, time 58781ms
rtt min/avg/max/mdev = 0.001/0.002/13.661/0.011 ms, pipe 2, ipg/ewma 0.007/0.006 ms
在执行命令的时候直接调整优先级
使用nice命令指定
[root@centos72 ~]# nice -n -5 ping -f 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
^C
--- 127.0.0.1 ping statistics ---
3272228 packets transmitted, 3272228 received, 0% packet loss, time 26347ms
rtt min/avg/max/mdev = 0.001/0.003/8.853/0.015 ms, pipe 2, ipg/ewma 0.008/0.005 ms
[root@centos72 ~]#
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu | grep ping
1158 ping -f 127.0.0.1 -5 94.6
1161 grep --color=auto ping 0 0.0
[root@centos72 ~]# nice -n 5 ping -f 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu | grep ping
1162 ping -f 127.0.0.1 5 110
1164 grep --color=auto ping 0 0.0
优先级高并不一定更快
[root@centos72 ~]# nice -n -11 ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.019 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.030 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.026 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.019/0.025/0.030/0.004 ms
[root@centos72 ~]# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.028 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.022 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.023 ms
^C
--- 127.0.0.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.022/0.024/0.028/0.006 ms
三注意事项——优先级之间的关系
(一)ni: nice值的优先级和pri优先级是相反的
nice值的优先级越高,那么对应的pri优先级越低
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu,pri | grep ping
1283 ping -f 127.0.0.1 -20 96.2 39
1360 grep --color=auto ping 0 0.0
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu,pri | tail
1099 [kworker/0:1] 0 0.0 19
1101 sshd: root@pts/2 0 0.7 19
1105 -bash 0 0.0 19
1143 [kworker/1:1] 0 0.0 19
1159 [kworker/1:2] 0 0.0 19
1165 [kworker/0:0] 0 0.0 19
1183 [kworker/0:2] 0 0.0 19
1184 [kworker/1:0] 0 0.0 19
1190 ps axo pid,cmd,ni,%cpu,pri 0 0.0 19
1191 -bash 0 0.0
[root@centos72 ~]# nice -n 10 ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.023 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.057 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.023 ms
64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.025 ms
64 bytes from 127.0.0.1: icmp_seq=11 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=12 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: icmp_seq=13 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=14 ttl=64 time=0.037 ms
64 bytes from 127.0.0.1: icmp_seq=15 ttl=64 time=0.023 ms
^C
--- 127.0.0.1 ping statistics ---
15 packets transmitted, 15 received, 0% packet loss, time 14000ms
rtt min/avg/max/mdev = 0.023/0.027/0.057/0.011 ms
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu,pri | tail
1101 sshd: root@pts/2 0 0.7 19
1105 -bash 0 0.0 19
1143 [kworker/1:1] 0 0.0 19
1159 [kworker/1:2] 0 0.0 19
1165 [kworker/0:0] 0 0.0 19
1183 [kworker/0:2] 0 0.0 19
1184 [kworker/1:0] 0 0.0 19
1192 ping 127.0.0.1 10 0.0 9
1193 ps axo pid,cmd,ni,%cpu,pri 0 0.0 19
1194 tail 0 0.0
[root@centos72 ~]# nice -n -10 ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.021 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.028 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.023 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.023 ms
^C
--- 127.0.0.1 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 4999ms
rtt min/avg/max/mdev = 0.021/0.024/0.028/0.003 ms
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu,pri | tail
1101 sshd: root@pts/2 0 0.6 19
1105 -bash 0 0.0 19
1143 [kworker/1:1] 0 0.0 19
1159 [kworker/1:2] 0 0.0 19
1165 [kworker/0:0] 0 0.0 19
1183 [kworker/0:2] 0 0.0 19
1184 [kworker/1:0] 0 0.0 19
1195 ping 127.0.0.1 -10 0.0 29
1196 ps axo pid,cmd,ni,%cpu,pri 0 0.0 19
1197 tail 0 0.0
注意帮助文档的此说明并不准确
[root@centos72 ~]# man ps | grep PRI
pri PRI priority of the process. Higher number means lower priority.
rtprio RTPRIO realtime priority.
数字越大优先级越高
所以帮助文档是有一定的bug的,不要迷信权威
[root@centos72 ~]# ps -C ping o pid,cmd,ni,%cpu,pri
PID CMD NI %CPU PRI
1246 ping 127.0.0.1 10 0.0 9
1248 ping 127.0.0.1 -10 0.0
在6上没有PRI的相关说明
[root@centos65 ~]# man ps | grep PRI
rtprio RTPRIO realtime priority.
(二)pri的优先级的值和早期系统优先级相反
也就是从139到0,早期的系统优先级是从0到139
所以pri的值越大优先级越高
[root@centos72 ~]# nice -n 30 ping 127.0.0.1
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu,pri | tail
1058 ping 8.8.8.8 0 0.0 19
1059 sshd: root@pts/1 0 0.1 19
1063 -bash 0 0.0 19
1086 sshd: root@pts/2 0 0.6 19
1090 -bash 0 0.0 19
1110 [kworker/1:1] 0 0.0 19
1113 [kworker/0:0] 0 0.0 19
1114 ping 127.0.0.1 19 0.0 0
1118 ps axo pid,cmd,ni,%cpu,pri 0 0.0 19
1119 tail 0 0.0
(三)实时优先级rtprio和nice优先级关系
从下图可以看出实时优先级和nice优先级对应系统优先级的一部分,实时优先级和nice优先级是没有交集的
ncie优先级又被称为动态优先级,比如占用的内存太多了就会自动的把优先级调小。
实时优先级是静态的优先级,指定好了就固定不变了。
调整实时优先级使用chrt
rtprio: 实时优先级
因为nice优先级不对应任何的实时优先级,所以无法显示实时优先级
[root@centos72 ~]# nice -n -20 ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.022 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.022/0.027/0.034/0.006 ms
[root@centos72 ~]# ps -C ping o pid,cmd,ni,%cpu,pri,rtprio | tail
PID CMD NI %CPU PRI RTPRIO
1260 ping 127.0.0.1 -20 0.0 39 -
7 [migration/0] - 0.0 139 99中139是最高的优先级,值越大优先级越高,
因为是pri优先级,和系统优先级是相反的
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu,pri,rtprio | head
PID CMD NI %CPU PRI RTPRIO
1 /usr/lib/systemd/systemd -- 0 0.0 19 -
2 [kthreadd] 0 0.0 19 -
3 [ksoftirqd/0] 0 0.0 19 -
5 [kworker/0:0H] -20 0.0 39 -
6 [kworker/u256:0] 0 0.0 19 -
7 [migration/0] - 0.0 139 99
8 [rcu_bh] 0 0.0 19 -
9 [rcu_sched] 0 0.0 19 -
10 [lru-add-drain] -20 0.0 39 -
看门狗监控内核状态的,最高优先级
就像国家的安全部分监控其他部门,比如明朝的锦衣卫
[root@centos72 ~]# ps axo pid,cmd,ni,%cpu,pri,rtprio | grep watch
11 [watchdog/0] - 0.0 139 99
12 [watchdog/1] - 0.0 139 99
1272 grep --color=auto watch 0 0.0 19 -
ps查看和调整优先级的更多相关文章
- linux ps查看进程命令
linux ps查看进程命令ps命令作用:将某个时间点的程序运作情况撷取下来 实例: [root@linux ~]# ps aux [root@linux ~]# ps -lA [root@linux ...
- 【Linux】常用指令、ps查看进程、kill杀进程、启动停止tomcat命令、查看日志、查看端口、find查找文件
1.说出 10 个 linux 常用的指令 1) ls 查看目录中的文件 2)cd /home 进入 '/ home' 目录:cd .. 返回上一级目录:cd ../.. 返回上两级目录 3)mkdi ...
- Java如何查看线程的优先级?
Java编程中,如何查看线程的优先级? 以下示例演示如何使用Thread类的getPriority()方法检查线程的优先级. package com.yiibai; public class Thre ...
- Linux常用指令---ps(查看进程)
Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...
- linux ps查看进程命令详解
http://linux.net527.cn/Linuxwendang/xitongguanliyuan/39094.htmlLinux操作系统PS命令详细解析 要对系统中进程进行监测控制,用 ps ...
- ps查看进程
ps:要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,而ps命令就是最基本同时也是非常强大的进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态.进程是否结束. ...
- Linux ps 查看进程
[root@wang /]# ps aux ps -elf ^C [root@wang /]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIM ...
- Linux:PS查看进程信息,和查看tomcat内存等信息
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/fly910905/article/deta ...
- 用ps 查看线程状态
ps -eLo pid,tid,class,rtprio,ni,pri,psr,pcpu,pmem,stat,wchan:30,comm 线程相关选项: THREAD DISPLAY H Show t ...
随机推荐
- 4,JPA
一,什么是JPA JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. JPA(Java Pers ...
- hdu1166:敌兵布阵(树状数组或线段树)
题目描述: 一堆废话不用看...... 输入: 第一行一个整数T,表示有T组数据.每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表 ...
- MySQL新建数据库时utf8_general_ci编码解释
utf8_unicode_ci和utf8_general_ci对中英文来说没有实质的差别.utf8_general_ci: 校对速度快,但准确度稍差.utf8_unicode_ci: 准确度高,但校对 ...
- oracle 远程访问
oracle 本机能连外部访问不了 新装的 oracle 数据库经常会出现本地计算机能连接,但是局域网内的其他计算机不能连接的问题,如果出现此问题可以参考此文来解决. 本文中用的数据库版本为 Orac ...
- 算法中时间复杂度概括——o(1)、o(n)、o(logn)、o(nlogn)
在描述算法复杂度时,经常用到 o(1), o(n), o(logn), o(nlogn) 来表示对应算法的时间复杂度, 这里进行归纳一下它们代表的含义:这是算法的时空复杂度的表示.不仅仅用于表示时间复 ...
- 13. Jmeter-定时器
Jmeter-定时器介绍与使用 固定定时器 Uniform Random Timer Precise Throughput Timer Constant Throughput Timer 高斯随机定时 ...
- js-xlsx sheet_to_json 读取小数位数变多
read as string . 例如:2.85 读取后变成 2.84999999999999999 这种. 以字符串形式读取. XLSX.utils.sheet_to_json(workbook.S ...
- 搜狗拼音、QQ拼音输入法、2345拼音输入法、百度输入法 、手心输入法对比。(个人体会)
搜狗拼音.QQ拼音输入法.2345拼音输入法.百度输入法 .手心输入法对比. 这几个输入法对比的感觉,做个记录.自己记录一下,如果恰巧有朋友也遇到类似的情况,仅供参考. 词库量 搜狗 > 百度 ...
- spring-data-neo4j了解
本项目demo地址[请阅读readme文件]: https://gitee.com/LiuDaiHua/project-neo4j 最近项目上要搭建一个关系图谱的东西,领导给了neo4j和d3两个概念 ...
- java中多种方式解析xml
第一种:DOM.DOM的全称是Document Object Model,也即文档对象模型.在应用程序中,基于DOM的XML分析器将一个XML文档转换成一个对象模型的集合(通常称DOM树),应用程序正 ...