OS Components
OS Components
A FEW TERMINOLOGIES
INTERRUPTS
• When the CPU is interrupted, it stops what it is doing and immediately
transfers execution to a fixed location.
• The fixed location usually contains the starting address where the
service routine for the interrupt is located.
• The interrupt service routine executes; on completion, the CPU resumes
the interrupted computation.
• An interrupt service (handler) routine is a procedure written
specifically to handle a system calls, exceptions, or interrupts.
• Although different phenomenon causes system calls, exceptions, and
interrupts, the structure of an interrupt service routine, or ISR (IHR), is
approximately the same for each of these.
User Program running
on the Computer
Interrupt is
User Program Serviced
Continues from the
interrupted point
SYSTEM CALLS
• A programmer initiated and expected transfer of control to a special
handler routine ( particularly input/output)
• In many respects, a system call is nothing more than a specialized
subroutine call.
• System Calls can be directly activated by the assembler invoking the
number of the desired interruption with the INT or SYSCALL or other
system instructions.
• Using system calls our programs become shorter
• Easy to understand
• Better performance due to short size
User Program running
System call or Software Interrupt on the Computer
(OS service call)
System Call is
User Program Serviced
Continues from the
interrupted point
• OS system calls
• easier to use but they are slower since they are implemented using
OS libraries
• BIOS system calls
• BIOS system calls are much faster
• Since they are part of the hardware, they are very basic and specific.
Programs are not portable.
Exceptions
Process management
Device management
Memory management
Interrupt handling
I/O communication
File system...etc..
There is a difference between kernel and OS. Kernel as described above is the heart of
OS which manages the core features of an OS while if some useful applications
and utilities are added over the kernel, then the complete package becomes an
OS. So, it can easily be said that an operating system consists of a kernel space
and a user space.
So, we can say that Linux is a kernel as it does not include applications like file- system
utilities, windowing systems and graphical desktops, system administrator
commands, text editors, compilers etc. So, various companies add these kind of
applications over linux kernel and provide their operating system like ubuntu,
suse, centOS, redHat etc.
3. Types Of Kernels
Earlier in this type of kernel architecture, all the basic system services like process and
memory management, interrupt handling etc were packaged into a single
module in kernel space. This type of architecture led to some serious drawbacks
like 1) Size of kernel, which was huge. 2)Poor maintainability, which means bug
fixing or addition of new features resulted in recompilation of the whole kernel
which could consume hours
2 Microkernels
This architecture majorly caters to the problem of ever growing size of kernel code,
which we could not control, in the monolithic approach. This architecture allows
some basic services like device driver management, protocol stack, file system
etc. to run in user space. This reduces the kernel code size and also increases the
security and stability of OS as we have the bare minimum code running in kernel.
So, if suppose a basic service like network service crashes due to buffer overflow,
then only the networking service's memory would be corrupted, leaving the rest
of the system still functional.
In this architecture, all the basic OS services, which are made part of user space, are
made to run as servers, which are used by other programs in the system through,
inter process communication (IPC). eg: we have servers for device drivers,
network protocol stacks, file systems, graphics, etc. Microkernel servers are
essentially daemon programs like any others, except that the kernel grants some
of them privileges to interact with parts of physical memory that are otherwise
off limits to most programs. This allows some servers, particularly device
drivers, to interact directly with hardware. These servers are started at the
system start-up.
So, what the bare minimum that microkernel architecture recommends in kernel
space?
Apart from the above, all other basic services can be made part of user space and can
be run in the form of servers.
Thread
A thread is a flow of execution through the process code, with its own program
counter that keeps track of which instruction to execute next, system registers
which hold its current working variables, and a stack which contains the
execution history.
A thread shares with its peer threads few information like code segment, data segment
and open files. When one thread alters a code segment memory item, all other
threads see that.
A thread is also called a lightweight process. Threads provide a way to improve
application performance through parallelism. Threads represent a software
approach to improving performance of operating system by reducing the
overhead thread is equivalent to a classical process.
Each thread belongs to exactly one process and no thread can exist outside a process.
Each thread represents a separate flow of control. Threads have been
successfully used in implementing network servers and web server. They also
provide a suitable foundation for parallel execution of applications on shared
memory multiprocessors. The following figure shows the working of a single-
threaded and a multithreaded process.
In multiple processing All threads can share same set of open files,
environments, each process child processes.
executes the same code but
has its own memory and file
resources.
If one process is blocked, then no While one thread is blocked and waiting, a
other process can execute second thread in the same task can run.
until the first process is
unblocked.
Advantages of Thread
• Threads minimize the context switching time.
• Use of threads provides concurrency within a process.
• Efficient communication.
• It is more economical to create and context switch threads.
• Threads allow utilization of multiprocessor architectures to a greater
scale and efficiency.
Types of Thread
Threads are implemented in following two ways −
• User Level Threads − User managed threads.
• Kernel Level Threads − Operating System managed threads acting on
kernel, an operating system core.
User Level Threads
In this case, the thread management kernel is not aware of the existence of threads.
The thread library contains code for creating and destroying threads, for passing
message and data between threads, for scheduling thread execution and for
saving and restoring thread contexts. The application starts with a single thread.
Advantages
• Thread switching does not require Kernel mode privileges.
• User level thread can run on any operating system.
• Scheduling can be application specific in the user level thread.
• User level threads are fast to create and manage.
Disadvantages
• In a typical operating system, most system calls are blocking.
• Multithreaded application cannot take advantage of multiprocessing.
Kernel Level Threads
In this case, thread management is done by the Kernel. There is no thread
management code in the application area. Kernel threads are supported directly
by the operating system. Any application can be programmed to be
multithreaded. All of the threads within an application are supported within a
single process.
The Kernel maintains context information for the process as a whole and for
individuals threads within the process. Scheduling by the Kernel is done on a
thread basis. The Kernel performs thread creation, scheduling and management
in Kernel space. Kernel threads are generally slower to create and manage than
the user threads.
Advantages
• Kernel can simultaneously schedule multiple threads from the same
process on multiple processes.
• If one thread in a process is blocked, the Kernel can schedule another
thread of the same process.
• Kernel routines themselves can be multithreaded.
Disadvantages
• Kernel threads are generally slower to create and manage than the user
threads.
• Transfer of control from one thread to another within the same process
requires a mode switch to the Kernel.
Multithreading Models
Some operating system provide a combined user level thread and Kernel level thread
facility. Solaris is a good example of this combined approach. In a combined
system, multiple threads within the same application can run in parallel on
multiple processors and a blocking system call need not block the entire process.
Multithreading models are three types
• Many to many relationship.
• Many to one relationship.
• One to one relationship.
Many to Many Model
The many-to-many model multiplexes any number of user threads onto an equal or
smaller number of kernel threads.
The following diagram shows the many-to-many threading model where 6 user level
threads are multiplexing with 6 kernel level threads. In this model, developers
can create as many user threads as necessary and the corresponding Kernel
threads can run in parallel on a multiprocessor machine. This model provides the
best accuracy on concurrency and when a thread performs a blocking system
call, the kernel can schedule another thread for execution.
User-level threads are faster to create and manage. Kernel-level threads are slower to create
Implementation is by a thread library at the user level. Operating system supports creation of Ke
Multi-threaded applications cannot take advantage of Kernel routines themselves can be multit
multiprocessing.
Difference between User-Level & Kernel-Level Thread