Linux下nice/renice命令小结
1. nice命令
内核根据进程的nice值决定进程需要多少处理器时间. nice值的取值范围是是: -20到20. 一个具有-20 的 nice 值的进程有很高的优先级. 一个 nice 值为 20 的进程的优先级则很低.
1) 用 ps axl 显示所有正在运行的进程的 nice 值
# ps axl
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
4 0 1 0 16 0 2172 552 - S ? 0:17 init [5]
1 0 3 1 34 19 0 0 ksofti SN ? 3:18 [ksoftirqd/0]
1 0 10 1 5 -10 0 0 worker S< ? 0:01 [events/0]
4 0 5145 1 25 10 32124 18592 - SNs ? 0:08 /usr/bin/python /usr/bin/rhn-applet-gui --sm-client-id default4
4 0 5147 5142 16 0 3528 604 - S ? 0:00 /sbin/pam_timestamp_check -d root
1 503 17552 4180 16 0 14208 3920 - S ? 0:01 /home/www/apache2/bin/httpd -f /home/www/apache2/conf/httpd.conf -k start
2) 如何给一个shell脚本分配一个低的优先级(更高的nice值)?
在下面的例子里, 当我在后台启动 nice-test.sh 脚本, nice 值为 0.
$ ./nice-test.sh &
[3] 13009
$ ps axl | grep nice-test
0 509 13009 12863 17 0 4652 972 wait S pts/1 0:00 /bin/bash ./nice-test.sh
[注: 第六列数值为 0 的是 nice 值]
现在, 以不同的 nice 值来执行相同的脚本, 如下所示:
$ nice -10 ./nice-test.sh &
[1] 13016
$ ps axl | grep nice-test
0 509 13016 12863 30 10 4236 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh
[注: 第六列数值为 10 的是该 shell 脚本的 nice 值]
3) 如何给一个shell脚本分配一个高的优先级(更低的nice值)?
下面的例子里, 分配给 shell 脚本 nice-test.sh 一个"-10"的 nice 值.
$ nice --10 ./nice-test.sh &
[1] 13021
$ nice: cannot set priority: Permission denied
注意: 只有 root 用户可以设置一个负的 nice 值. 用 root 用户登录再次尝试. 注意在下面的nice 命令里的 10 前面有一个双破折号.
# nice --10 ./nice-test.sh &
[1] 13060
# ps axl | grep nice-test
4 0 13060 13024 10 -10 5388 964 wait S< pts/1 0:00 /bin/bash ./nice-test.sh
[注: 第六列数值为-10 的是该 shell 脚本的 nice 值]
2. renice命令
renice 可以给正在运行的进程设置调度优先级.
1) 怎样降低一个运行进程的优先级(增加 nice值)?
下面的例子里, 一个存在的 shell 脚本运行时的 nice 值为 10. (ps 输出的第 6 列)
$ ps axl | grep nice-test
0 509 13245 13216 30 10 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh
为增加 nice 值(因此降低优先级), 按如下方法执行 renice 命令.
$ renice 16 -p 13245
13245: old priority 10, new priority 16
$ ps axl | grep nice-test
0 509 13245 13216 36 16 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh
[注: 现在, nice-test.sh (PID 13245)的第 6 列显示新的 nice 值是 16]
2) 怎样增加运行进程的优先级(减少 nice值)?
下面的例子里, 一个已有的 shell 脚本运行时 nice 值为 10. (ps 输出第 6 列)
$ ps axl | grep nice-test
0 509 13254 13216 30 10 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh
为提升其优先级, 赋予其一个较低的nice值. 然而, 只有root可以提升运行进程的优先级, 否则你会得到以下错误信息.
$ renice 5 -p 13254
renice: 13254: setpriority: Permission denied
Login as root to increase the priority of a running
process
$ su -
# renice 5 -p 13254
13254: old priority 10, new priority 5
# ps axl | grep nice-test
0 509 13254 13216 25 5 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh
注: 第 6 列现在显示了一个较低的 nice 值 5(提升的优先级)]
Linux下nice/renice命令小结的更多相关文章
- Linux下lz4解压缩命令小结
lz4是一个让"人见人爱.花见花开"的压缩算法,能够在多核上很好的扩展.lz4在压缩率上略微逊色, 但是在解压速度上有着惊人的优势 (大概是gzip的3倍(多次测试对比)).因为压 ...
- Linux下内存查看命令
在Linux下面,我们常用top命令来查看系统进程,top也能显示系统内存.我们常用的Linux下查看内容的专用工具是free命令. Linux下内存查看命令free详解: 在Linux下查看内存我们 ...
- linux下显示dd命令的进度:
linux下显示dd命令的进度: dd if=/dev/zero of=/tmp/zero.img bs=10M count=100000 想要查看上面的dd命令的执行进度,可以使用下面几种方法: 比 ...
- [转] 关于linux下通过shell命令(自动)修改用户密码
关于linux下通过shell命令(自动)修改用户密码 2012-04-23 18:47:39 分类: 原文地址:关于linux下(自动)修改用户密码 作者:ubuntuer 本文章总结了如何手动.自 ...
- linux下安装7z命令及7z命令的使用
本文主要介绍了在linux下安装7z命令的方法,同时介绍了7z命令的使用.7z压缩格式拥有众多优点,具有极高的压缩比率,如果你还不了解,请看文章:7z格式.LZMA压缩算法和7-Zip详细介绍. re ...
- 将linux下的rm命令改造成移动文件至回收站【转】
转自:http://blog.csdn.net/a3470194/article/details/16863803 [-] 将linux下的rm命令改造成移动文件至回收站 将AIX下的rm命令改造成移 ...
- Linux下使用mail命令发送邮件
因为需要经常备份网站的数据,所以了解并学习了下linux下如何通过shell来发送邮件,这里以CentOS为例,使用mail命令来进行外部邮件的发送.mail命令的语法如下: Usage: mail ...
- linux下常用FTP命令
linux下常用FTP命令 1. 连接ftp服务器 1. 连接ftp服务器格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1b)服 ...
- Linux下的管道命令有这些:
Linux下的管道命令有这些: 选取命令:cat grep 排序命令:sort wc uniq 双向重定向:tee 字符转换命令: tr, col, join, paste, expand 切割命令: ...
随机推荐
- lanuchy快捷操作
down arrow: display history shift+delete: remove the item from the distory
- 在Python中,令values=[0,1,2];values[1]=values,为何结果是[0,[...],2]?
转载自:http://www.zhihu.com/question/21000872/answer/16856382>>> values = [0, 1, 2] >>&g ...
- 横向滚动条展示 css
<div class="shuaixuan" style="overflow:hidden;"> <div style="ov ...
- java03实验截图
- leetcode 146. LRU Cache ----- java
esign and implement a data structure for Least Recently Used (LRU) cache. It should support the foll ...
- Linux驱动设计—— 内外存访问
本节对内外存访问做详细的介绍. 驱动程序加载成功的一个关键因素,就是内核能够为驱动程序分配足够的内存空间.这些空间一部分用于驱动程序必要的数据结构,另一部分用于数据的交换.同时,内核也应该具有访问外部 ...
- as3 中 textfiled的htmltext 的常用属性
http://blog.sina.com.cn/s/blog_6d193c030100x6ud.html <a> 超链接标签 属性:href: 链接地址 target: 目标窗口 可取值为 ...
- 论文笔记之: Recurrent Models of Visual Attention
Recurrent Models of Visual Attention Google DeepMind 模拟人类看东西的方式,我们并非将目光放在整张图像上,尽管有时候会从总体上对目标进行把握,但是也 ...
- caffe: train error: Serializing 25 layers--- Check failed: proto.SerializeToOstream(&output)
I0221 21:47:41.826748 6797 solver.cpp:259] Train net output #0: loss = 0.00413362 (* 1 = 0.0041 ...
- CENTOS GUI
http://unix.stackexchange.com/questions/181503/how-to-install-desktop-environments-on-centos-7 How t ...