Linux under nice/renice Command summary __linux

Source: Internet
Author: User
Linux under nice/renice command summary2010-03-30 12:58 1.1.1 Nice Command

The kernel determines how much processor time the process requires, depending on the nice value of the process. The value range for the nice value is:-20 to 20. A process with a nice value of 20 has a high priority. A process with a nice value of 20 has a low priority.

1 to display the nice value of all running processes with PS Axl


# PS Axl

F UID PID PPID PRI NI VSZ RSS wchan STAT TTY time COMMAND

4 0 1 0 0 2172 552-s? 0:17 Init [5]

1 0 3 1 0 0 ksofti SN? 3:18 [ksoftirqd/0]

1 0 1 5-10 0 0 worker s<? 0:01 [events/0]

4 0 5145 1 32124 18592-sns? 0:08/usr/bin/python/usr/bin/rhn-applet-gui--sm-client-id DEFAULT4

4 0 5147 5142 0 3528 604-s? 0:00/sbin/pam_timestamp_check-d Root

1 503 17552 4180 0 14208 3920-s? 0:01/home/www/apache2/bin/httpd-f/home/www/apache2/conf/httpd.conf-k Start

2 How to assign a low priority to a shell script (a higher nice value)?


In the following example, when I start the nice-test.sh script in the background, the nice value is 0.

$./nice-test.sh &

[3] 13009

$ ps Axl | grep nice-test

0 509 13009 12863 0 4652 972 wait S pts/1 0:00/bin/bash./nice-test.sh

[Note: The Sixth column value is a nice value of 0]

Now, execute the same script with a different nice value, as follows:

$ nice-10./nice-test.sh &

[1] 13016

$ ps Axl | grep nice-test

0 509 13016 12863 4236 968 wait SN pts/1 0:00/bin/bash./nice-test.sh

[Note: The sixth column value of 10 is the nice value for the shell script]

3 How to assign a high priority to a shell script (lower nice value)?

In the following example, a nice value of "-10" is assigned to the shell script nice-test.sh.

$ nice--10/nice-test.sh &

[1] 13021

$ nice:cannot Set Priority:permission denied

Note: Only the root user can set a negative nice value. Log on again with root user. Notice that there is a double dash in front of 10 in the Nice command below.

# 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

[Note: The Sixth column value is-10 is the nice value of the shell script]


1.1.2 Renice Command

Renice can set the scheduling priority for a running process.

1 How to reduce the priority of a running process (add nice value)?


In the following example, the nice value for a existing shell script is 10. (6th column of PS output)

$ ps Axl | grep nice-test

0 509 13245 13216 5244 968 wait SN pts/1 0:00/bin/bash./nice-test.sh

To increase the Nice value (and therefore lower the priority), execute the renice command as follows.

$ renice 16-p 13245

13245:old priority, new priority 16

$ ps Axl | grep nice-test

0 509 13245 13216 5244 968 wait SN pts/1 0:00/bin/bash./nice-test.sh

[Note: Now, the 6th column of nice-test.sh (PID 13245) shows that the new nice value is 16]

2 How do I increase the priority of the running process (reduce the nice value)?


In the following example, an existing shell script runs with a nice value of 10. (PS output 6th column)

$ ps Axl | grep nice-test

0 509 13254 13216 4412 968 wait SN pts/1 0:00/bin/bash./nice-test.sh

To elevate its priority, give it a lower nice value. However, only root can elevate the priority of the running process, otherwise you will get the following error message.

$ 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, new priority 5

# PS Axl | grep nice-test

0 509 13254 13216 5 4412 968 wait SN pts/1 0:00/bin/bash./nice-test.sh

Note: The 6th column now shows a lower nice value of 5 (elevated priority)]


--end--

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.