Linux process Management (2) Four of the relevant commands
To set or adjust a process priority command: nice Rnice
Nice command
Nice-run a program with modified scheduling priority
Modify scheduling its process priority when running a program
Format and Usage:
Nice [options] [command [args]]
- N # :# indicates to set this program nice value,-20 to The higher the value, the higher the priority
Note:-20to the +of each Nicevalues correspond to each other (Centos5in the100-139,CentOS6in the0-39) +Priority value, the higher the priority value, Nicethe smaller the value, the faster the corresponding process runs and consumes moreCPURun resource space. Of course, there are real-time priorities, that is, when the priority is the same, it is compared by real-time priority, the real-time priority value is99-0, where the greater the value, the higher the corresponding priority.
Case:
# Open a nice - value vim in the pts/0 terminal Process
[Email protected] ~]# nice-n vim file.txt
# Switch to the pts/1 terminal to see its nice value
[Email protected] ~]# PS Axo Pid,comm,ni | grep ' \<vim ' 46853 vim 19
Parse: Why this is shown here , because The nice value is set to a minimum of -20, the maximum is Nice is above the maximum or below the minimum value, which the system considers to be the default maximum or minimum value.
# Open two background vim process, Nice value is -10
[[email protected] ~]# nice-n -10 vim file1 &[1] 46941
# When the second one is opened, the first process is stopped
[[email protected] ~]# nice-n -10 vim file2 &[2] 46942 [1]+ Stopped nice-n -10 vim file1
# view information in the jobs job queue at this time
[Email protected] ~]# jobs[1]-Stopped nice-n -10 vim file1[2]+ Stopped nice-n -10 VI M file2
Parse:+ represents the Occupy queue. Description, at this time vim in the same terminal priority storage 2 number of jobs in the memory of data division.
# view its priority and nice values
# The prioity value of the two value is the same as the nice value
[[email protected] ~]# ps-c vim-o pid,comm,ni,pri pid COMMAND ni pri 46941 vim-10 46942 vim -10 29
Note: The prioity value here is not the same as the above-mentioned nice value of the four priority
Rnice Command
Usage options:
PID prioity + specified prioity = nice
rnice prioity PID # = corresponding process The specified prioity original prioity = new
Note: In either case, the average user can self-adjust the nice value of their process .
Case:
# Reset the second vim, and the PID for the 46906 process of Nice
[[email protected] ~]# renice-n ' pgrep-f ' ^vim[[:space:]].*2 ' 46942 (process ID) old priority-10, new priority 19
Parse: This shows a piece of information, saying that the new nice value is , for this process the original priority value ( plus the Set Nice values, and 29+ ( -10) =19 .
# view two again vim priority of the process and nice
[[email protected] ~]# ps -c vim -o pid,cmd,comm,ni,pri pid cmd COMMAND ni pri 46941 vim file1 vim -10 29 46942 vim file2 vim 19 0
parsing: Because the nice value of the vim file2 process is a, The greater the Nice value, the lower the priority value.
test Normal users can only adjust the nice value of their own process
# switch to normal user
[Email protected] ~]# su-hadooplast login:wed Sep 7 21:47:06 EDT on PTS/2
# Open the vim process with nice value
[Email protected] ~]$ nice-n vim file1 &[1] 47037
# Check in the background job there's just the process
[Email protected] ~]$ jobs[1]+ Stopped nice-n vim file1
# View the vim process Nice value and priority value
[Email protected] ~]$ PS Axo Pid,comm,ni,pri,rtprio | grep vim 47037 vim 10 9-
# Adjust Nice value to current priority + ( -9), and 9-9=0
[[email protected] ~]$ Renice-n-9 47037renice:failed to set priority for 47037 (process ID): Permission denied
Resolution: The process was originally Nice value of ten, if set to 0 is equivalent to providing priority, and as a normal user, is not able to preempt other users ' processes.
# Then you can't turn it down, set your nice value directly to 29-10=19, raise the Nice value
[Email protected] ~]$ renice 4703747037 (process ID) old priority, new priority 19
Resolution:The nice value is a friendly value and can only be sacrificed to the priority of its own process to provide more CPU resource space for other users ' processes .
This article from "Meng Tian pa-it garbage Collection Station" blog, declined reprint!
Linux process Management (2) Four of the relevant commands