使用nice命令调整进程优先级

Adjusting Process Priority with nice  

When Linux processes are started, they are started with a specific priority. By default, all regular processes are equal and are started with the same priority, which is the priority number 20. In some cases, it is useful to change the default priority that was assigned to the process when it was started. You can do that using the  nice  and  renice  commands. Use  nice  if you want to start a process with an adjusted priority. Use  renice  to change the priority for a currently active process. Alternatively, you can use the  r  command from the  top  utility to change the priority of a currently running  process.

Changing process priority may make sense in two different scenarios. Suppose, for example, that you are about to start a backup job that does not necessarily have to finish fast. Typically, backup jobs are rather resource intensive, so you might want to start it in a way that it is not annoying other users too much, by lowering its priority.

Another example is where you are about to start a very important calculation job. To ensure that it is handled as fast as possible, you might want to give it an increased priority, taking away CPU time from other processes.

On earlier Linux versions, it could be dangerous to increase the priority of one job too much, because other processes (including vital kernel processes) might risk being blocked out completely. On current Linux kernels, the situation is not that urgent anymore:

■ Modern Linux kernels differentiate between essential kernel threads that are started as real-time processes and normal user processes. Increasing the priority of a user process will never be able to block out kernel threads or other processes that were started as real-time processes.

■ Modern computers often have multiple CPU cores. A single threaded process that is running with the highest priority will never be able to get beyond the boundaries of the CPU it is running on.

When using nice or renice to adjust process priority, you can select from values ranging from -20 to 19. The default niceness of a process is set to 0 (which results in the priority value of 20). By applying a negative niceness, you increase the priority. Use a positive niceness to decrease the priority. It is a good idea not to use the ultimate values immediately. Instead, use increments of 5 and see how it affects the application.

TIP Do not set process priority to -20; it risks blocking other processes from getting served.

EXAMPLES:

Let’s take a look at examples of how to use nice and renice . The command nice -n 5 dd if=/dev/zero of=/dev/null & starts an infinite I/O-intensive job, but with an adjusted niceness so that some place remains for other processes as well. To adjust the niceness of a currently running process, you need the PID of that process. The following two commands show how ps aux is used to find the PID of the dd job from the previous example. Next, you see how the renice command is used to change the niceness of that command:

[[email protected] tmp]# nice -n 5 dd if=/dev/zero of=/dev/null &
[1] 2872
[[email protected] tmp]# jobs
[1]+  Running                 nice -n 5 dd if=/dev/zero of=/dev/null &

1. Use ps aux | grep dd to find the PID of the dd command that you just started. The PID is in the second column of the command output.

[[email protected] tmp]# ps aux | grep dd
root         2  0.0  0.0      0     0 ?        S    Jun27   0:00 [kthreadd]
root        43  0.0  0.0      0     0 ?        S<   Jun27   0:00 [ipv6_addrconf]
dbus       618  0.0  0.0  34948  1856 ?        Ssl  Jun27   0:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root      2872 99.9  0.0 107936   620 pts/1    RN   04:23   2:37 dd if=/dev/zero of=/dev/null
root      2883  0.0  0.0 112644   956 pts/1    R+   04:26   0:00 grep --color=auto dd

2. Use renice -n 10 -p 1234 (assuming that 1234 is the PID you just found). 
Note that regular users can only decrease the priority of a running process. You must be root to give processes increased priority.

[[email protected] tmp]# renice -n 10 -p 2872
2872 (process ID) old priority 5, new priority 10
时间: 2024-10-05 05:07:47

使用nice命令调整进程优先级的相关文章

12.2、linux作业管理、调整进程优先级

1.linux作业分类: 前台作业:foreground,通过终端启动,且启动后会一直占据终端 后台作业:background,可以通过终端启动,但启动后会转入后台,释放终端占用 作业可能包含多个程序,也可以只包含一个程序. 2.作业被转入后台方法: 运行中的作业:ctrl+z 注意:送往后台,作业会转为停止态 尚未运行的作业:command &  //命令command后跟一个&,表示作业送往后台 注意:此类作业虽然被送往后台,但是他依然与终端相关,如果希望把送往后台的作业剥离与终端的关

Linux进程管理命令之调整进程优先级

可通过nice值调整的优先级范围是100~139,分别对应于-20~19 进程启动时,其nice值默认为0,换算到优先级为120 nice 以指定的nice值运行命令 nice的默认值是0 -n是指定进程运行的nice值 renice 调整一个已经运行进程的nice值 查看进程的nice值和优先级 原文地址:http://blog.51cto.com/yueyue207/2106003

调整进程优先级

查看优先级ps -e -o class,rtprio,pri,nice,cmd 手动调整优先级100-139:nice nice N COMMAND 程序一启动就用这个优先级 renice -n PID 对已经运行的程序设置优先级1-99: chrt -f -p PID 对FF的进行调整 chrt -r -p POD 对RR的进行调整 chrt 也可以调整100-139的 不要-f就可以 ------------------------------------------------------

Ubuntu—终端命令调整窗口的大小

1,查看窗口大小 current 1280x768 是我当前电脑的窗口大小,下面提供的是可以修改的窗口大小. $ xrandr 2.修改窗口大小 示例: $ xrandr -s 1024x768 原文地址:https://www.cnblogs.com/summer1019/p/10349976.html

Linux改变进程优先级的nice命令

前言: VPS普遍性能不高,很多人可能有这样一个感受,在执行du.tar等命令时,会造成系统负载飙升,Apache响应缓慢.这时nice命令改变进程优先级可能能缓解这种状况.nice命令用于调整Linux系统中进程的优先级. 通俗地讲,Linux系统中,进程有-19到19这39个优先级.-19最优先,19最不优先.进程的默认优先级为0.如果希望将进程调整为最优先,则将进程的nice值设置为-19:如果希望进程最不优先,占用最少的系统CPU时间,则将其设置为19. 1.新建一个进程并设置优先级 将

#22 进程、优先级管理命令:vmstat、pmap、htop、glances、dstat、kill、killall、pkill、bg、fg、nice...

进程之间可以通信的:IPC,inter-process communication 1.signal(信号) 2.semaphore(旗语) 3.shared memory(SHM) 4.socket 有效的信号表示方法: 1.使用信号的数字编码进行表示: 2.使用信号的完整名称进行表示: 3.使用信号的简写名称进行表示,简写名称就是完整名称中不包含"SIG"的其余部分: 常用的信号: 1.SIGHUP:无需关闭对应进程而让其重新读取其自身的配置文件: 2.SIGINT:终止正在运行的

Linux之进程管理(2)相关命令之四

Linux之进程管理(2)相关命令之四 设置或调整进程优先级命令: nice  rnice nice 命令 nice - run a program with modified scheduling priority 运行一个程序时修改调度其进程优先级 格式及用法: nice  [options]  [command [args]] -n  # :#表示要设置此程序nice值,-20到19,值越下,优先级越高 注:-20到19的每个nice值分别对应(Centos5中为100-139,CentO

linux 进程优先级 调度 nice pri

转:http://www.linuxidc.com/Linux/2016-05/131244.htm 深入 Linux 的进程优先级 [日期:2016-05-11] 来源:liwei.life  作者:@orroz [字体:大 中 小] 为什么要有进程优先级?这似乎不用过多的解释,毕竟自从多任务操作系统诞生以来,进程执行占用cpu的能力就是一个必须要可以人为控制的事情.因为有的进程相对重要,而有的进程则没那么重要. 本文作者:邹立巍 Linux系统技术专家.目前在腾讯SNG社交网络运营部 计算资

(转)Linux常用性能检测命令

一.uptime     Uptime命令的显示结果包括服务器已经运行了多长时间,有多少登陆用户和对服务器性能的总体评估(load average).load average值分别记录了上个1分钟,5分钟和15分钟间隔的负载情况,load average不是一个百分比,而是在队列中等待执行的进程的数量.如果进程要求CPU时间被阻塞(意味着CPU没有时间处理它),load average值将增加.另一方面,如果每个进程都可以立刻得到访问CPU的时间,这个值将减少.   UP kernel下的loa