Operating System
Lakshmi
(Assistant Professor)
MPGI, Kanpur
Spooling (Simultaneous Peripheral Operation On-line)
• Spooling is an acronym for simultaneous peripheral operation on-line.
• Spooling is a process in which data is temporarily held in memory or other
volatile storage to be used by a device or program.
• It refers to putting jobs in queue or in buffer, a special area in memory or on a
disk where a device can access them when it is ready.
The most common implementation of spooling found in typical I/O devices such
as the keyboard, mouse and printer. For example, In a computer system, I/O
devices such as printer are very slow relatives to the performance of the rest of
the system. In printer spooling the documents/files that are sent to the printer are
first stored in memory, once the printer is ready, it fetches the data and prints it.
Advantages:
Simultaneous processing
Continues workflow
Reduced wait time
Structure of Operating System
A system as large and complex as a modern operating system must be
engineered carefully if it is to function properly and be modified easily. A
common approach is to partition the task into small components rather than
have one monolithic system.
(I) Simple / Monolithic structure
Such operating system do not have well defined structure and well defined
structure and they are small, simple and limited system.
These type of OS cause the entire system to crash if one of the user program
fails.
Example, MS-DoS operating system has four layer, ROM BIOS device driver,
MS-DoS Driver, application programs and system programs.
Advantage of simple structure
• Each level can be defined independently and
when necessary can interact with one another.
• It will be simpler to design, manage and update.
Disadvantage of simple structure
• When a user program fails, the OS as whole
crasher.
• No abstraction for data hiding due to
interconnected.
(II) Layered structure
An OS can be broken into pices and retain much more control over the
system.
In this OS is broken into number of layers (or levels).
The bottom layer (layer-1 ) is hardware; the highest (layer-N) is the user
interface.
The operation (routines ) can be invoke operations
on lower level layer.
This simplifies the debugging process, if lower layer
are debugged and an error occur during debugging,
then the error must be on thar layer only, lower level
layer have already been debugged.
Advantage:
Lower approach provides modularity.
Debugging is easier as lower layer are debugged and then upper layer are
checked.
Disadvantage:
It takes careful planning to design and construct the layers. Since higher
layer only utilize the function of lower layer.
(III) Micro-kernel structure
Kernel: The core of an OS acting as central hub that manages everything such
as hardware resources and processors called kernel.
Imagine you have small but powerful OS (core). This core is called
microkernel.
Across the microkernels have different specialize parts called servers. Each
server handles specific task like managing files, controlling I/O devices.
The thinking power of microkernel as the brain of OS and responsible for
essential functions like memory management and process scheduling.
The structure design of this OS by removing un-necessary components from
the kernel and implementing them as system and user programs. And the
resultant structure in small kernel called micro-kernel.
Advantage of this structure are that all new devices need to be added to user space
and does not require the kernel to be modified. So, it is more secure, and reliable as
if a service fails then rest of the OS remains untouched. E.g. Mac OS.
• Advantage
• If any service fails then rest of the micro-kernel remains untouched and
works fine.
• It makes the OS portable.
• Disadvantage
• System is complex to be constructed.
• Increased inter module communication reduces system performance or
system overhead.
(IV) Modular structure
The kernel has only set of core components and other services are added as
dynamically loadable modules to the kernel either during run time or boot
time. Any module can communicate with the help of kernels.
Operating system components (services)
These are following components of OS:
• Kernel: The kernel is the core component of OS. It provides essential
services such as process management, device management, memory
management and system call handling.
• Process management: This component is responsible for creating,
scheduling and terminating process.
• Memory management: It ensure that each process has access to
the memory if needed. It allocate and deallocate memory dynamically.
• File management: The file management component organize and
control how data is stored retrieved on the storage devices.
• I/O device management: This component handles input and
output operations between the computer and external devices. It co-
ordinate data transfer between processes and I/O devices.
• Device management: Device management control the interaction
between the OS and hardware devices.
• User interface: The user interfaces components provide a way for user to
interact with the OS and run application.
• Network management: Networking components enable communication
between computer and devices over a network managing network
connections, providing network services such as file sharing and etc.
• Security management: It ensures the integrity, confidentiality and
availability of system resources means user authentication, encryptions
and other security features.
• Kernel
The kernel is core component of an Operating System. It acts as bridge
between software application and computer hardware. It manages system
resources and providing essential services to enable the execution of the
program.
Operations of kernel
It has same functionalities as OS. Such as process management, memory
management, I/O device management, security management, network
managements, user interference and etc.
Types of Kernel
(I) Reentrant kernel
(II) Monolithic kernel
(III) Microlithic kernel
• Reentrant kernel
A reentrant kernel is a type of OS kernel that allows multiple processes to
safely and efficiently execute the same code simultaneously.
It means this kernel can handle multiple request from different processes
at the same time without causing conflicts and errors.
Example: A disc read is an example of this. When a user program requests
a disc read, the scheduler will delegate the CPU to another process (kernel
thread) until the disc controller issues an interrupt indicating that the data
is accessible and our thread can be resumed. This process can still access
I/O, such as user input, which requires kernel functions. The system
remains responsive, and the amount of CPU time wasted as a result of IO
delays is reduced. The original function (whatever requested data) would
be blocked in a non-reentrant kernel until the disc read was completed.
Monolithic Kernel Vs Microkernel
Monolithic Kernel Microkernel
Structure Large, single pices of software that include Small, modular design with basic
all functions. functionalities in the kernel, other services
implement as user space process.
Size Typically large in size Typically small
Complexity Higher complexity, as all functions Lower complexity, as function seperated.
integrated
Performance Generally, higher performance due to direct May have lower performance due to
access to hardware and fewer context additional overhead from message passing
switches. between user.
Flexibility Less flexible for adding or modifying More flexible for adding or modifying function.
functions.
Maintain It take less time It is simple to maintain
Debugging & speed Debugging is difficult. While execution speed Debugging is simple. In microkernel, the
is high. execution speed is low.
What is Thread?
Threads are often called “lightweight processes” because they share some features of
processes but are smaller and faster. Each thread is always part of one specific
process.
A thread has three states: Running, Ready and Blocked. A thread takes less time to
terminate as compared to the process but unlike the process, threads do not isolate.
Advantage:
When there is a lot of computing and input/output (I/O) work, threads help tasks run at
the same time, making the app faster.
Another advantage for having threads is that since they are lighter weight than
processes, they are easier (i.e., faster) to create and destroy than processes.
Disadvantage:
Threads in the same process are not completely independent like separate processes.
They share the same memory space including global variables.
This means one thread can accidentally change or even erase another thread’s data as
there is no protection between them.
ULT vs KLT
User level threads (ULT) Kernel level threads (KLT)
ULTs are created by the application packages or Scheduling must be through OS.
libraries at the user level without talking any support
of OS.
Thread management is done at user mode. Thread management is done at kernel mode.
Fastest context switching. Lowest context switching.
Entire process gets blocked when a thread requires No other process get blocked except the specific
an I/O device or any system call. thread which needs I/O will be blocked.
What is a Program?
When we execute a program that was just compiled, the Operating System will
generate a process to execute the program. Execution of the program starts via
GUI mouse clicks, command line entry of its name, etc. A program is a passive
entity as it resides in the secondary memory, such as the contents of a file stored
on disk. One program can have several processes.
Features of a Program
• Multiple programs can be executed by a single user.
• All program instructions are stored in main memory, which is provided by the
operating system.
• It is an inert thing. All it is a file with some instructions that need to be executed.
• It is devoid of a control block.
• The secondary memory of the system houses it.
• One program may be linked to multiple processes. For example, a browser may
have multiple tabs active at once.
What is a Process?
The term process (Job) refers to program code that has been loaded into a
computer’s memory so that it can be executed by the central processing unit
(CPU). A process can be described as an instance of a program running on a
computer or as an entity that can be assigned to and executed on a processor. A
program becomes a process when loaded into memory and thus is an active
entity.
Features of process:
• Every process has a certain collection of data associated with it. For instance, the name of its
parents, the location of the memory space that has been allotted, and security attributes like
ownership rights and credentials.
• A process can only exist for the duration that it is being performed.
• System resources are assigned to processes. Two instances are file descriptors and network
ports.
• The process is an active entity.
• It has a lot of resources.
• For it to function, it needs resources like memory address, CPU, and I/O.
Process state diagram: Each process is represented by a PCB. It is
associated with every process to maintain process ID, starting address of
page table, open file information, CPU information, security information
etc.
• Differences
(I) Shell & Kernel
Shell Kernel
Definition A shell is an environment or a special user It is hard and core part of OS that
programs which provides an interface to user manages operations of computer and
to use OS services it execute hands on input hardware.
provided by USER.
Interaction Directly interact with user It interact directly with software.
Function Execute user programs and run commands Manage system resources and do
operations.
Location Run on top of OS Run at heart of the OS
Customization Can be customized with plugin and script Highly specialized and not user
modifiable.
User interference Text based interference Not directly visible to another.
Error handling Report user error and provide feedback Manage system error and exception.
Example Powershell, CMD Linux kernel, windows NT
(II) Program vs process
Program Process
The program contains a set of instructions designed to The process is an instance of an executing program.
complete a specific task.
A program is a passive entity as it resides in the The process is an active entity as it is created during
secondary memory. execution and loaded into the main memory.
Program exists at a single place and continues to exist The process exists for a limited period as it gets
until it is deleted. terminated after the completion of the task.
A program is a static entity. A program is a static entity.
The program does not have any resource requirement, it The process has a high resource requirement, it needs
only requires memory space for storing the resources like CPU, memory address, and I/O during its
instructions. lifetime.
The program does not have any control block. Process has its control block called Process Control
Block.
The program has two logical components: code and In addition to program data, a process also requires
data. additional information required for the management and
execution.
The program does not change itself. Many processes may execute a single program. Their
program code may be the same but program data may be
different. these are never the same.
Program contains instructions . The process is a sequence of instruction execution.
(II) Process vs thread
Process Thread
Process means program in execution. Thread means segment of a process.
A process takes more time to terminate. A thread takes less time to terminate.
It takes more time for creation. It takes less time for creation.
It also takes more time context switching. It takes less time for context switching.
A process is less efficient in terms of communication. Thread is more efficient in terms of communication.
Multiprogramming holds the concept of multi-process. We don't need multi programs in action for multiple
threads because a single process consists of multiple
threads.
Every process runs in its own memory. Threads share the memory.
If one process is blocked, then it will not affect the If a user-level thread is blocked, then all other user-level
execution of other processes. threads are blocked.
A process has its own Process Control Block, Stack, and Thread has Parents’ PCB, its own Thread Control Block,
Address Space. and Stack and common Address space.
• How is system call made?
Making a system call: When a user level process running an application need to
perform an operation that required access with hardware then it make a system
calls.
To initialize, a system call, the process typically uses a special instruction or
software interrupt provided by the CPU, this instructions or signals to the CPU
that the process is requesting a services from the OS.
How is system call handled?
When CPU receive a request for a system call, it switches from user mode to
kernel mode to give the OS direct access to system resources.
The kernel then identifies the types of system call being requested. Then kernel
validate the parameters provided by the process to ensure they are valid and
authorized.
Once the parameters are validated the kernel perform the requested operation on
behalf of the process. After completion of operation, the kernel returns the result
of the system call to the calling process.
Example of standard C library
• File system call in process management
fork()- To create a new process
exe()- To execute a new program in a process
wait()- To wait until a created process complete its execution
exit() - To exit from a process identifier of current process
getpid() - To get a process identifier of current process
getppid()- To get parent process identifier
brk()- To increase/decrease the data segment size of a process.