next up previous contents
Next: Mainataing the Kernel Up: Managing Processes Previous: Terminating Processes   Contents

程序的執行序

  1. nice 值
    1. 一般使用者的 nice 值為 0 ~ 19
    2. root 可用的 nice 值為 -20 ~ 19
  2. 觀察priority與CPU使用關係
    ##terminal 1-1
    [root@deyu ~]# cat /dev/zero > /dev/null &
    [1] 12977
    [root@deyu ~]# cat /dev/zero > /dev/null &
    [2] 12978
    [root@deyu ~]# cat /dev/zero > /dev/null &
    [3] 12979
    [root@deyu ~]# cat /dev/zero > /dev/null &
    [4] 12980
    
    ##terminal 2-1
    [root@deyu ~]# top
    
    top - 17:33:03 up 10:51,  9 users,  load average: 2.42, 0.68, 0.23
    Tasks: 214 total,   5 running, 209 sleeping,   0 stopped,   0 zombie
    Cpu(s):  3.2%us, 96.8%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
    Mem:   3021464k total,  1293324k used,  1728140k free,   105432k buffers
    Swap:   253936k total,        0k used,   253936k free,   470852k cached
    
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    12977 root      20   0 98.5m  552  444 R 49.6  0.0   0:42.67 cat                
    12979 root      20   0 98.5m  552  444 R 49.6  0.0   0:25.05 cat                
    12978 root      20   0 98.5m  552  444 R 49.4  0.0   0:26.92 cat                
    12980 root      20   0 98.5m  552  444 R 49.4  0.0   0:24.55 cat 
    ....
    
    ##terminal 1-2
    [root@deyu ~]# renice -n 10 12977
    12977: old priority 0, new priority 10
    
    ##terminal 2-2
    ....
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    12979 root      20   0 98.5m  552  444 R 66.4  0.0   1:47.96 cat                
    12978 root      20   0 98.5m  552  444 R 64.7  0.0   1:48.84 cat                
    12980 root      20   0 98.5m  552  444 R 61.4  0.0   1:45.55 cat                
    12977 root      30  10 98.5m  552  444 R  7.0  0.0   1:34.61 cat 
    
    ##terminal 1-3
    [root@deyu ~]# renice -5 12978
    12978: old priority 0, new priority -5
    
    ##terminal 2-3
    ....
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    12978 root      15  -5 98.5m  552  444 R 99.8  0.0   5:59.59 cat                
    12979 root      20   0 98.5m  552  444 R 47.0  0.0   5:46.56 cat                
    12980 root      20   0 98.5m  552  444 R 46.9  0.0   5:42.90 cat                
    12977 root      30  10 98.5m  552  444 R  5.4  0.0   2:00.67 cat  
    
    ##terminal 1-4
    [root@deyu ~]# nice -n 5 cat /dev/zero > /dev/null &
    [5] 13130
    
    ##terminal 2-4
    ....
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    12978 root      15  -5 98.5m  552  444 R 99.7  0.0   8:29.42 cat                
    12980 root      20   0 98.5m  552  444 R 40.2  0.0   6:51.01 cat                
    12979 root      20   0 98.5m  552  444 R 40.1  0.0   6:54.59 cat                
    13130 root      25   5 98.5m  552  444 R 13.1  0.0   0:03.88 cat                
    12977 root      30  10 98.5m  552  444 R  4.2  0.0   2:08.24 cat     
    
    r key 12980 4 #renice pid 12980 with nice value 4
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    12978 root      15  -5 98.5m  552  444 R 99.7  0.0   9:44.45 cat                
    12979 root      20   0 98.5m  552  444 R 41.0  0.0   7:25.43 cat                
    12980 root      24   4 98.5m  552  444 R 40.9  0.0   7:21.84 cat                
    13130 root      25   5 98.5m  552  444 R 13.3  0.0   0:13.93 cat                
    12977 root      30  10 98.5m  552  444 R  4.4  0.0   2:11.54 cat  
    
    k key 12978 15 # kill pid 12978 with signal 15
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    12979 root      20   0 98.5m  552  444 R 98.7  0.0   8:13.12 cat                
    12980 root      24   4 98.5m  552  444 R 47.3  0.0   7:42.19 cat                
    13130 root      25   5 98.5m  552  444 R 35.7  0.0   0:29.89 cat                
    12977 root      30  10 98.5m  552  444 R 11.8  0.0   2:16.78 cat
    


2015-04-13