3. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Modify process execution priorities
In Linux kernel, the scheduler is responsible for deciding which process is going to occupy the
CPU's attention for the next millisecond.
One of the factors for making this decision is the priority or niceness of the process.
Process priority
3
1.Using nice you can change the niceness of new processes.
2.Using renice you can change execution priorities of running processes.
• Nice directly maps to a kernel call of the same name.
• Used to invoke a utility or shell script with a particular priority, giving the process more/less CPU time
than other processes.
• A niceness of −20 is the highest priority and 19 or 20 is the lowest priority.
• The default niceness for processes is inherited from its parent process, usually 0.
https://en.wikipedia.org/wiki/Nice_%28Unix%29#Etymology
4. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Modify process execution priorities
nice - To change the priority of a process that is started
You make it behave more nicely so it does not monopolize the CPU
Using nice
4
Niceness values range from: -20 (not at all nice, very important) to +19 (20) (very nice).
-n switch specifies just how nice the process should be
• nice -n 15 process – start the process with a niceness of 15
• nice -15 process – start the process with a niceness of 15
• nice -n -15 process – start the process with a niceness of 15 (higher priority)
"niceness" originates from the idea that a process with a higher niceness value is "nicer" to other
processes in the system.
This is why the nice number is usually called niceness: a job with a high niceness is very kind to the users
of the system (it runs at low priority), while a job with little niceness hogs the CPU.
The niceness of a process is inherited by the processes it creates.
If the login sequence for a user sets the niceness of that user's processes, all processes run by the user are also nice.
5. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Modify process execution priorities
renice - used to set the priority of processes that are already running
Using renice
5
renice can zap specific processes or the processes owned by a user or a group.
• renice +1 -p 14292 – make process 14292 just a little nicer
• renice +2 -u jack – make all of Jack's processes two notches nicer.
• renice +3 -g users – make the processes whose group is “users” three notches nicer.
1.Users can only increase the niceness of their own processes.
2.Root can increase or decrease the niceness of any process.
3.Processes with positive niceness get low priority, and often a process with niceness 19 or
20 only runs when nothing else in the system wants to.
4.Starting a process with nice(19) will make it go really slow
6. CoreLinuxforRedHatandFedoralearningunderGNUFreeDocumentationLicense-Copyleft(c)AcácioOliveira2012
Everyoneispermittedtocopyanddistributeverbatimcopiesofthislicensedocument,changingisallowed
Modify process execution priorities
ps (process status) reports niceness of processes in the column STAT
If process has any degree of niceness, the status column includes N.
ps and niceness
6
ps can be convinced to display the niceness of each process
– but you wouldn't want to do this. (It's probably not in exam).
jack@foo:~> ps x
PID TTY STAT TIME COMMAND
2461 ? SN 0:00 /usr/sbin/sshd
2463 pts/1 SN 0:00 -bash
2510 pts/1 RN 0:00 ps x
Ex:
Ex:
george@foo:~> ps -eo pid,nice,user,args --sort=user | head
PID NI USER COMMAND
2636 10 george /usr/sbin/sshd
2638 10 george -bash
2663 10 george ps -eo pid,nice,user,args --sort=user
2664 10 george head
1196 0 at /usr/sbin/atd
589 0 bin /sbin/portmap
21330 10 michael /bin/sh /usr/X11R6/bin/kde
21380 10 michael kdeinit: Running...
21383 10 michael kdeinit: dcopserver --nosid