Pages

Sunday, October 4, 2015

Process priority in Linux

Linux uses the priority based scheduling algorithm. It ranks the processes based on their worth and need for processor time. The Linux kernel implements two separate priority ranges.

1. Nice Values:
             It is a number between -20 and +19 with a default value of 0. Larger nice values correspond to a lower nice values i.e. it is nice to the other processes in the system. Thus, processes with lower nice values receive a greater proportion of the system processor as compared to processes with a higher nice value. In Mac OS X nice values control over the absolute time-slice. In Linux, it is the control over the proportion of the time-slice.

ps -el commmand gives the processes and their corresponding nice values.

The getpriority and setpriority functions gets and sets the nice values. (http://linux.die.net/man/2/setpriority)

Nice values can be set from the linux command line using the nice command. To set lower priority to a process to avoid slow down of other processes, we can use the following command.

$ nice -n 19 tar cvzf archive.tgz largefile

2. Real-time priority:
         These priority values range from 0 to 99 inclusive with default value being 0. Unlike nice values, higher real-time priority values mean higher priority. All real time processes are at a higher real-time priority value than other processes.

The command below gives the list of processes and their real-time priority values under the column marked RTPRIO.

ps -eo state,uid,pid,ppid,rtprio,time,comm

A value of "-" means the process is not real time.






Friday, October 2, 2015

Types of Kernel

Kernels can be classified into the following categories:

1. Monolithic
                In this type of architecture, all the basic system services like process and memory management, interrupt handling etc were packaged into a single module in kernel space.

Earlier version of this architecture had the following drawbacks:

      a. The size of kernel was huge.
      b. Bug fixing or addition of new features resulted in                  recompilation of whole kernel.

However, the modern architecture which Linux uses is much better and includes feature to dynamically load the modules thus facilitating easy extension of OS's capabilities. 

Linux follows the monolithic modular approach.

2. Microkernels:
           In this type of architecture, only the bare minimum is implemented in kernel space which includes managing memory protection, process scheduling and inter process communication (IPC) thus decreasing the kernel size and increasing security and stability of OS. Other basic services like device driver management,protocol stack, file systems, graphics, etc are implemented in user space and are run as servers. These servers are different from other user space programs as kernel grants them permissions to interact with physical memory which is usually off limits to most programs. Thus these serves can interact directly with the hardware. These services are started at system startup.

QNX follows the microkernel approach.

3. Hybrid Kernel:
            Hybrid kernel is the most successful kernel implementation and is used in operating systems like Windows NT and above and Mac OS X. This type of kernel are extension of microkernel with some properties of monolithic kernel. Hybrid kernels are microkernel that has some non-essential code in kernel space in order for the code to run faster than it would have been in user space. Unlike monolithic kernel, they are unable to load modules at run time.

The hybrid kernel approach combines the speed and simpler design of a monolithic kernel with the modularity and execution safety of a microkernel.