Kernel in Operating Systems

Operating Systems

Kernel in Operating Systems:

Kernel in operating systems is a program that decides that which hardware is to be with which software. It also decides that how many resources and memory should assign to a is one program running at all times on the computer. It is a core part of operating system. Kernel mostly contains in protected are of memory to prevent it from being is attended that nobody can interact with kernel program to make instructions false. If CPU is the brain of computer then the kernel is heart of operating system.

First of all when computer starts first kernel is loaded because it is the centered module of Operating System. Operating system is responsible for doing this, that 90% of time is the kernel we are talking about. It mostly control the CPU, device and manage the memory. If kernel does not control the currently running processor, then system is not aware that what is happening in it.

Another important thing about kernel is that it remains same after the system shut down. It always reserve some space from the memory which can only be used by the kernel and other applications program cannot use that space. Dual mode allows operating system to protect itself and other system component. These dual modes are Users Mode and Kernel Mode. When system uses dual mode then user mode cannot access the directly all resources but only by using kernel mode.

  • Mode bit given by the hardware which is 0 for kernel mode and 1 for user mode.
  • Mode bit provides the ability to distinguish when the system running user mode or kernel mode.
  • All privileged instruction can be executed by kernel mode only.
  • When a system call makes it change mode to kernel, return of the call results it to user mode.




Types of Kernel Mode


There are various types of kernel namely monolithic kernel, Microkernel, Hybrid kernel, Exo Kernel, and Nano-Kernel. Most widely used kernel is Monolithic kernel and Microkernel. Below are the details of these.

The Monolithic kernel

The monolithic is older kernel used in UNIX, MS-DOS and early MAC-OS.

In the monolithic kernel, every basic service like the process and memory management, interrupt handling and I/O communication, file system, etc. run in kernel space. It is constructed in a layered fashion, application at the top, then the libraries in user-space.

The inclusion of all basic service in the kernel has the following drawback:

  • The kernel size increases, lack of extensibility and the bad maintainability.
  • Bug- fixing or the addition of new features means a recompilation of the whole kernel.
  • It is time and resource consuming because the compilation of a new kernel can take several hours and a lot of memory.

To overcome the drawbacks of the monolithic kernel, microkernel came into existence.

Advantages of Monolithic Kernel

Some of the advantages of monolithic kernel are:

  • The execution of the monolithic kernel is quite fast as the services such as memory management, file management, process scheduling etc. Are         implemented under the same address space.
  • A process runs completely in a single address space in the monolithic kernel.
  • The monolithic kernel is a static single binary file.


Disadvantages of Monolithic Kernel

Some of the disadvantages of monolithic kernel are:

  • If any service fails in the monolithic kernel, it leads to the failure of the entire system.
  • To add any new service, the entire operating system needs to be modified by the user


The Microkernel

In the microkernel, process resides in User Space in the form of servers. There is the server for managing memory issues, one server does process management, and another one manages drivers, and so on. Because the servers do not run in kernel “space” context switches” are not required, to allow user processes to enter the privileged mode.

Hybrid kernel

This type of kernel combines the best properties of both micro-kernel and Mono-kernel. The idea behind a hybrid kernel is to have a kernel structure similar to that of a microkernel but implementation structure is same as monolithic kernel.

Nano kernel

A Nano kernel is a small kernel that offers hardware abstraction but without system services.




Kernel Architecture: UNIX Kernel

  • It is responsible for scheduling running of user and other processes.
  • It is responsible for allocating memory. It is responsible for managing the swapping between memory and disk.
  • It is responsible for moving data to and from the peripherals.
  • It receives service requests from the processes and honoursthem.

User Mode and Kernel

       At any one time we have one process engaging the CPU. This may be a user process or a system routine (like ls, chomp) that is providing a service. The following three situations result in switching to kernel mode from user mode of operation:

  1. The scheduler allocates a user process a slice of time (about 0.1 second) and then system clock interrupts. This entails storage of the currently running process status and selecting another runnable process to execute. This switching is done in kernel mode. A point that ought to be noted is: on being switched the current process’s priority is re-evaluated (usually lowered).

The UNIX priorities are ordered in decreasing order as follows:

  • HW errors
  • Clock interrupt
  • Disk I/O
  • Keyboard
  • SW traps and interrupts
  1. 2. Services are provided by kernel by switching to the kernel mode. So if a user program needs a service (such as print service, or access to another file for some data) the operation switches to the kernel mode. If the user is seeking a peripheral transfer like reading a data from keyboard, the scheduler puts the currently running process to “sleep “mode.
  2. Suppose a user process had sought a data and the peripheral is now ready to provide the data, then the process interrupts. The hardware interrupts are handled by switching to the kernel mode. In other words, the kernel acts as the via-media between all the processes and the hardware as depicted.


System Calls in UNIX

The following are typical system calls in UNIX:

Intent of a process The C function call

  • Open a file open.
  • Close a file close.
  • Perform I/O read/write.
  • Send a signal kill (actually there are several signals) Create a pipe.
  • Create a socket.
  • Duplicate a process fork.
  • Overlay a process execute.
  • Terminate a process exit


UNIX Kernel Steps

Typically, UNIX kernels execute the following secure seven steps on a system call:

  1. 1. Arguments (if present) for the system call are determined.
  2. 2. Arguments (if present) for the system call are pushed in stack.
  3. 3. The state of calling process is saved in a user structure.
  4. The process switches to kernel mode.
  5. The syscallvector is used as an interface to the kernel routine.
  6. 6. The kernel initiates the services routine and a return value is obtained from the kernel service routine.
  7. The return value is converted to a c version (usually an integer or a long integer). The value is returned to process which initiated the call. The system also logs the useridof the process that initiated that call.


An Example of a System Call

Let us trace the sequence when a system call to open a file occurs.

  • User process executes a syscallopen a file.
  • User process links to a c runtime library for open and sets up the needed parameters in registers.
  • A SW trap is executed now and the operation switches to the kernel mode. -The kernel looks up the syscallvector to call “open“-The kernel tables are modified to open the file. -Return to the point of call with exit status.
  • Return to the user process with value and status.
  • The user process may resume now with modified status on file or abort on error with exit


Process States in UNIX

UNIX has the following process state transitions:

Idle —-> runnable—–> running.

Running —-> sleep (usually when a process seeks an event like I/O, it sleeps awaiting event completion). Running —-> suspended (suspended on a signal).

Running —-> Zombie (process has terminate but has yet to return to its exit code to parent. In UNIX every process reports its exit status to the parent.)

Sleeping —> runnable

Suspended—> runnable

Note that it is the sleep operation which gives the user process an illusion of synchronous operation.


How does Kernel process differ from User Process?

  1. The first major key difference between the kernel process and other processes lies in the fact that kernel also maintains the needed data-structures on behalf of UNIX. Kernel maintains most of this data-structure in the main memory itself. The OS based paging or segmentation cannot swap these data structures in or out of the main memory.
  2. 2. Another way the kernel differs from the user processes is that it can access the scheduler. Kernel also maintains a disk cache, basically a buffer, which is synchronisedever so often (usually every 30 seconds) to maintain disk file consistency. During this period all the other processes except kernel are suspended. Finally, kernel can also issue signals to kill any process (like a process parent can send a signal to child to abort). Also, no other process can abort kernel.

Region Tables in UNIX

A region table stores the following information.

  • Pointers to i-nodes of files in the region.
  • The type of region (the four kinds of files in UNIX).
  • Region size.
  • Pointers to page tables that store the region.
  • Bit indicating if the region is locked.
  • The process numbers currently accessing the region.


Scheduler -1

Most UNIX schedulers follow the rules given below for scheduling:

  1. Usually a scheduler reevaluates the process priorities at 1 second interval. The system maintains queues for each priority level.
  2. Every tenth of a second the scheduler selects the topmost process in the runnable queue with the highest priority.
  3. If a process is runnable at the end of its allocated time, it joins the tail of the queue maintained for its priority level.
  4. If a process is put to sleep awaiting an event, then the scheduler allocates the processor to another process.
  5. If a process awaiting an event returns from a system call within its allocated time interval but there is a runnable process with a higher priority than the process is interrupted and higher priority, process is allocated the CPU.

Scheduler -2

1- Periodic clock interrupts occur at the rate of 100 interruptions per second. The clock is updated for a tick and process priority of a                   running process is decremented after a count of 4 ticks. The priority is calculated as follows:

2- Priority = (CPU quantum used recently)/ (a constant) + (base priority) + (the nice setting).

3 – Usually the priority diminishes as the CPU quantum rises during the window of time allocated. As a consequence compute intensive                processes are penalisedand processes with I/O intensive activity enjoy higher priorities.



Visit this for more topics on Operating Systems

Was this helpful?

1 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *