PROCESS SCHEDULING
NICE / RENICE
·
TO ALTER DEFAULT PRIORITY OF PROCESS’S
·
Every process has a nice value ranging from
0-39
·
Higher the nice value lower the priority
·
By default user process starts with nice value
20
·
NICE command is used to alter the default
priority at starting time, means at the time of execution
·
Later if we want to change pri. Of a running
process, we need to use RENICE
Let’s try to understand this via examples
root@sol-test-2:>/# nice -n 10 find ./
-name core &
[1] 27955
Well… I have to find an imp file and I know
that server is too busy… so I don’t want to put extra burden on server in terms
of resources… so I had give
Nice –n 10
Understand ?
no… ok let’s find some more
nice –n 10 … means the new value for nice is
10
Let’s check what it is showing in ps –el
root@sol-test-2:>/# ps -el |grep -i find
0
O 0 27955 27951 15 99 30 ? 421
pts/2 0:28 find
Well it is 30 now (I had increased the size
and make it bold)… so why 30 ?
We know that the default is 20 and I am simply
telling nice to (–n 10)… increase the value by 10
So it is now 20+10=30
Good… Now next example
I have to find an imp file and I know that
server is too busy…and I know that if I fire that command simply then it will
be on server that when he is going to assign resources to my process… but my
work is on very urgent and I can’t let it on servers mercy… I want it now on
top priority… so
root@sol-test-2:>/# nice -n -10 find ./
-name core &
[1] 27963
Well … marked the difference in commands ??
Find out… just a – sign in front of 10 … let’s
see the result
root@sol-test-2:>/# ps -el |grep -i find
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0
S 0 27963 27951 2 39 10 ? 421
? pts/2 0:02 find
See the nice value… now it is 20-10 =10
This will results in faster execution of
command
root@sol-test-2:>/# nice -n -19 find ./
-name core &
[1] 27966
root@sol-test-2:>/# ps -el |grep -i find
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0
O 0 27966 27951 1
40 1 ? 421
pts/2 0:01 find
This will run like rocket… 20-19 = 1
Let’s see the difference …
root@sol-test-2:>/# time nice -n -19 find
./ -name core
==================o/p removed=================
./hgfs/VM_SHARE/x86/nmap-6.40/nmap-6.40/zenmap/radialnet/core
real
0m45.682s
user
0m0.524s
sys
0m27.616s
root@sol-test-2:>/# time nice -n -10 find
./ -name core
==================o/p removed=================
real
0m48.916s
user
0m0.541s
sys
0m29.158s
there is minor difference in execution time…
but we can see the real difference when server is heavily loaded
root@sol-test-2:>/# nice -n 19 find ./
-name core &
[1] 27977
root@sol-test-2:>/# ps -el |grep -i find
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0
O 0 27977 27951 8 99 39 ?
421 pts/2 0:08 find
root@sol-test-2:>/# nice -n 15 find ./
-name core &
[1] 27987
root@sol-test-2:>/# ps -el |grep -i find
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0
S 0 27987 27951 1 39 35 ?
421 ? pts/2 0:01 find
Well … I think these are sufficient to
understand the importance & working of NICE.
This was all about Pri scheduling of a new
process… what about the running processes ??
RENICE
Well… I got complaint that server is running
slow… there might be several issues but this may be a solution… will check prstat and found that several
useless / less important services are
running (excluding system services)
Now I will change their nice value to higher
so that system will merely consider them and assign
freed resources to other processes.
root@sol-test-2:>/# ps -el |grep -i mail
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0 S
0 940 1
0 40 20 ?
2252 ? ? 0:06 sendmail
0 S
25 939 1
0 40 20 ?
2252 ? ? 0:02 sendmail
I selected mail service to be renice
root@sol-test-2:>/# renice -n 5 940
just like nice I had given renice –n 5
<process id>
root@sol-test-2:>/# ps -el |grep -i mail
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0 S
0 940 1
0 55 25 ? 2252
? ? 0:06 sendmail
0 S
25 939 1
0 40 20 ?
2252 ? ? 0:02 sendmail
Well… we can see here that renice has done its
job
root@sol-test-2:>/# renice -n 10 940
Again changed the nice value for same PID
root@sol-test-2:>/# ps -el |grep -i mail
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0 S
0 940 1
0 85 35 ? 2252
? ? 0:06 sendmail
0 S
25 939 1
0 40 20 ?
2252 ? ? 0:02 sendmail
Well.. what happened here ? why 35 ?
… it was already reniced to 25 so 25+10 =35
root@sol-test-2:>/# renice -n 5 940
Again tried
root@sol-test-2:>/# ps -el |grep -i mail
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0 S
0 940 1
0 97 39 ?
2252 ? ? 0:06 sendmail
0 S
25 939 1
0 40 20 ?
2252 ? ? 0:02 sendmail
Well… now it should be 35+5 =40 but it is 39
Let’s try one more time
root@sol-test-2:>/# renice -n 5 940
Let’s see this time it is adding 39+5 or not ?
root@sol-test-2:>/# ps -el |grep -i mail
F S
UID PID PPID
C PRI NI ADDR SZ
WCHAN TTY TIME CMD
0 S
0 940 1
0 97 39 ?
2252 ? ? 0:06 sendmail
0 S
25 939 1
0 40 20 ?
2252 ? ? 0:02 sendmail
Well… same here also…
Its default limit is 0-39
Some more examples ….
root@sol-test-2:>/# renice -n -20 940
root@sol-test-2:>/# ps -el |grep -i mail
0
S 0
940 1 0 40 19 ?
2252 ? ? 0:06 sendmail
0
S 25
939 1 0 40
20 ? 2252
? ? 0:02 sendmail
root@sol-test-2:>/# renice -n -10 940
root@sol-test-2:>/# ps -el |grep -i mail
0
S 0
940 1 0
40 9 ? 2252
? ? 0:06 sendmail
0
S 25
939 1 0 40
20 ? 2252
? ? 0:02 sendmail
root@sol-test-2:>/# renice -n -0 940
root@sol-test-2:>/# ps -el |grep -i mail
0 S 0
940 1 0
40 9 ? 2252
? ? 0:06 sendmail
0
S 25
939 1 0 40
20 ? 2252
? ? 0:02 sendmail
root@sol-test-2:>/# renice -n -5 940
root@sol-test-2:>/# ps -el |grep -i mail
0
S 0
940 1 0
40 4 ? 2252
? ? 0:06 sendmail
0
S 25
939 1 0 40
20 ? 2252
? ? 0:02 sendmail
OK.. done with renice … now the load on my
server is reduced and I want my default nice value back…
root@sol-test-2:>/# renice 0 940
Just see… no –n and 0 and it will understand
what I want to say…
root@sol-test-2:>/# ps -el |grep -i mail
0
S 0
940 1 0 40
20 ? 2252
? ? 0:06 sendmail
0
S 25
939 1
0 40 20 ?
2252 ? ? 0:02 sendmail
No comments:
Post a Comment