Module 1
Module 1
a task.
Operating System is a system software that acts as an intermediary between a user and Computer
Hardware to enable convenient usage of the system and efficient utilization of resources.
The commonly required resources are input/output devices, memory, file storage space, CPU etc.
The operating system acts as a manager of the above resources and allocates them to specific
programs and users, whenever necessary to perform a particular task.
Therefore operating system is the resource manager i.e. it can manage the resource of a computer
system internally.
The resources are processor, memory, files, and I/O devices. In simple terms, an operating
system is the interface between the user and the machine
Architecture of an Operating System
Operating system is the most important program that runs on a computer. OS is considered as the
backbone of a computer, managing both software and hardware resources.
They are responsible for everything from the control and allocation of memory to recognizing input
from external devices and transmitting output to computer displays.
They also manage files on computer hard drives and control peripherals, like printers and scanners.
Operating systems monitor different programs and users, making sure everything runs
smoothly,without interference, despite the fact that numerous devices and programs are used
simultaneously.
An operating system also has a vital role to play in security. Its job includes preventing unauthorized
users from accessing the computer system.
MEMORY MANAGEMENT:
Memory management refers to management of Primary Memory or Main Memory. Main memory is
a large array of words or bytes where each word or byte has its own address.
Main memory provides a fast storage that can be accessed directly by the CPU.
o Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part is not in use.
o In multiprogramming, the OS decides which process will get memory when and how much.
o Allocates the memory when a process requests it to do so.
o De-allocates the memory when a process no longer needs it or has been terminated.
PROCESSOR MANAGEMENT:
In multiprogramming environment, the OS decides which process gets the processor when and for
how much time. This function is called process scheduling.
ACTIVITIES of processor management
o Keeps tracks of processor and status of process. The program responsible for this task is known as
traffic controller.
o Allocates the processor (CPU) to a process.
o De-allocates processor when a process is no longer required.
DEVICE MANAGEMENT:
An Operating System manages device communication via their respective drivers.
ACTIVITIES of device management
o Keeps tracks of all devices. Program responsible for this task is known as the I/O controller.
o Decides which process gets the device when and for how much time.
o Allocates the device in the efficient way.
o De-allocates devices.
FILE MANAGEMENT:
A file system is normally organized into directories for easy navigation and usage. These directories
may contain files and other directions.
ACTIVITIES of file management
o Keeps track of information, location, uses, status etc. The collective facilities are often known as file
system.
o Decides who gets the resources.
o Allocates the resources.
o De-allocates the resources
Since main memory (primary storage) is volatile and too small to accommodate all data and programs
permanently, the computer system must provide secondary storage to back up main memory.
Most modern computer systems use disks as the principle on-line storage medium, for both programs
and data.
ACTIVITIES are,
o Free-space management (paging/swapping)
o Storage allocation (what data goes where on the disk)
o Disk scheduling (Scheduling the requests for memory access).
NETWORKING:
A distributed systems are a collection of processors that do not share memory, peripheral devices, or
a clock.
The processors in a distributed system vary in size and function. They may include small
processors,workstations, minicomputers and large, general-purpose computer systems.
The processors in the system are connected through a communication-network ,which are configured
in a number of different ways i.e.., Communication takes place using a [Link] network may be
fully or partially connected .
The communication-network design must consider routing and connection strategies, and the
problems of contention and security.
A distributed system provides user access to various system resources.
Access to a shared resource allows:
o Computation Speed-up
o Increased functionality
o Increased data availability
o Enhanced reliabilit………..y
PROTECTION SYSTEM:
If a computer system has multiple users and allows the concurrent execution of multiple processes,
then the various processes must be protected from one another's activities.
Protection refers to mechanism for controlling the access of programs, files, memory segments,
processes(CPU) only by the users who have gained proper authorization from the OS.
The protection mechanism must:
Generations of OS
.
Batch-processing operating system was very popular in the 1970s. In batch operating system the
jobs were performed in batches. This means Jobs having similar requirements are grouped and
executed as a group to speed up processing. Users using batch operating systems do not interact
with the computer directly. Each user prepares their job using an offline device for example a
punch card and submits it to the computer operator. Once the programmers have left their
programs with the operator, they sort the programs with similar needs into batches.
Batch-O S
SYSTEM CALLS:
System calls provide the interface between a process and the operating system.
These calls are generally available as assembly-language instructions.
Some systems also allow to make system calls from a high level language, such as C, C++and Perl
(have been defined to replace assembly language for systems programming). As an example of how
system calls are used,consider writing a simple program to read data from one file and to copy them to
another file.
The first input that the program will need is the names of the two files:
o The input file
o The output file
Once the two file names are obtained, the program must open the input file and create the output file.
Each of these operations requires another system call and may encounter possible error conditions.
o When the program tries to open the file, it may find that no file of that name exists or that the file is
protected against access.
If the input file exists, then we must create a new output file.
We may find an output file with the same name.
o This situation may cause the program to abort (a system call), or
o We may delete the existing file (another system call).
In an interactive system another option is to ask the user ( a sequence of system calls to output the
prompting message and to read response from the keyboard) whether to replace the existing file or to
abort the program.
2l;’
Now that both the files are setup, we enter a loop that reads from the input file (a system call)and writes
to the output file (another system call).
Each read and write must return status information regarding various possible error conditions.
o On input,
the program may find that the end of file has been reached, or
that a hardware failure occurred in the read (such as a parity error).
o On output,
Various errors may occur, depending on the output device (such as no more disk space, physical end
of tape, printer out of paper).
Finally, after the entire file is copied, The program may close both files (another system call), writes a
message to the console(more system calls), and finally terminates normal (the final system call).
Three general methods are used to pass parameters between a running program and the operating
system.
o Simplest approach is to pass parameters in registers.
o Store the parameters in a table in memory, and the table address is passed as a parameter in a register
(in the cases where parameters are more than registers).
o Push (store) the parameters onto the stack by the program, and pop off the stack by operating system.
SIMPLE STRUCTURE:
Many commercial systems do not have well-defined structures. Frequently,such operating systems
started as small, simple, and limited systems and then grew beyond their original scope.
MS-DOS is an example of such a system. It was originally designed and implemented by a few
people who had no idea that it would become so popular.
MS-DOS:
UNIX:
UNIX is the another system limited by hardware functionality. It consists of two separable parts
o System programs
o Kernel
LAYERED APPROACH:
A system can be made modular in many ways. One method is the layered approach, in which the
operating system is broken up into a number of layers (levels), each built on top of lower layers.
The bottom layer (layer 0) is the hardware; the highest (layer N) is the user interface as shownin
below. With modularity, layers are selected such that each uses functions (operations) and services of
only lower-level layers.
Fig:1.7 A Layered Operating System
A layered design was first used in the operating system. Its six layers are as follows:
LAYER 5 User Programs
LAYER 4 Buffering for Input and
Output
LAYER 3 Operator Console Device
Driver
LAYER 2 Memory Management
LAYER 1 CPU Scheduling
LAYER 0 Hardware
Working of Kernel
The kernel is the first part of the OS loaded into memory during boot, and it stays resident while the system is
running.
It operates in a privileged mode (kernel mode), separate from user mode for applications; user apps can’t
directly access hardware or critical resources.
Applications make requests to the kernel via system calls (or software interrupts). The kernel handles these by
switching from user mode to kernel mode.
Kernel executes the requested operation (e.g. file I/O, process creation, memory allocation).
On completion, kernel returns result (or error) to user space.
Kernel does context switching as needed (scheduler picks next process/thread) to allow multitasking.
MICRO KERNELS:
This method structures the operating system by removing all non essential components from the
kernel and implementing them as system and user-level programs i.e., moves as much from the kernel
into ―user‖ space which results is a smaller kernel.
Micro kernels typically provide minimal process and memory management, in addition to a
communication facility.
The main function of the micro kernel is to provide a communication facility between the client
program and the various services that are also running in user space.
Communication takes place between user modules using message passing. They communicate
indirectly by exchanging messages with the micro kernel.
One benefit of the micro kernel approach is ease of extending the operating system. All new services
are added to user space and consequently do not require modification of the kernel.
The micro kernel also provides more security and reliability, since most services are running as user
—rather than kernel—processes.
This micro kernel is a smaller kernel, which allows a only fewer changes in the operating system.
BENEFITS :
o Easier to extend a microkernel
o Easier to port the operating system to new architectures
o More reliable (less code is running in kernel mode)
o More secure
DRAWBACKS:
o Microkernels can suffer from performance decreases due to increased system function overhead.
Exokernel
An Exokernel OS design pushes the boundaries of minimalism. Applications are given
direct access to hardware resources, allowing them to manage resources and make
decisions that the kernel previously made.
The Exokernel Architecture
Now, let's explore the Exokernel architecture and its core principles:
1. Resource Exposure
In an Exokernel, programs have direct access to hardware resources such the CPU, memory,
and I/O units. Applications may now handle these resources with greater precision because
they have fine-grained control over them.
3. Minimalism
Exokernels take a straightforward stance. They leave high-level services and resource
management to application-level libraries and only offer the absolute necessities in
abstractions. This minimalism encourages adaptability and effectiveness.
4. Flexibility
Exokernels adopt a direct posture. They only provide the bare minimum in abstractions,
leaving high-level services and resource management to application-level libraries. This
minimalism promotes efficacy and adaptability.
Virtual Machines
A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating
system kernel as though they were all hardware.
A virtual machine provides an interface identical to the underlying bare hardware.
The operating system creates the illusion of multiple processes, each executing on its own processor with
its own (virtual) memory.
The resources of the physical computer are shared to create the virtual machines.
✦ CPU scheduling can create the appearance that users have their own processor.
✦ Spooling and a file system can provide virtual card readers and virtual line printers.
✦ A normal user time-sharing terminal serves as the virtual machine operator’s console.
System Models
INTRODUCTION TO PROCESSES:
A process is basically a program in execution. The execution of a process must progress in a sequential
fashion.
A process will need certain resources—such as CPU time, memory, files, and I/O devices —to
accomplish its task.
These resources are allocated to the process either when it is created or while it is executing.
Definition:A process is defined as an entity which represents the basic unit of work to be
implemented in the system.
PROCESSES:
A process is mainly a program in execution where the execution of a process must progress in a
sequential order or based on some priority or algorithms.
In other words, it is an entity that represents the fundamental working that has been assigned to a
system.
When a program gets loaded into the memory, it is said to as process. This processing can be
categorized into 4 sections. These are:
o Heap
o Stack
o Data
o Text
A process generally also includes the process stack, which contains temporary data (such as function
parameters, return addresses, and local variables), and a data section, which contains global variables.
A process may also include a heap, which is memory that is dynamically allocated during process run time.
STACK - The process Stack contains the temporary data such as method/function parameters, return
address and local variables.
HEAP - This is dynamically allocated memory to a process during its run time.
TEXT - This includes the current activity represented by the value of Program Counter and the
contents of the processor's registers.
DATA - This section contains the global and static variables.
We emphasize that a program by itself is not a process; a program is a passive entity, such as a file
containing a list of instructions stored on disk (often called an executable file), whereas a process is an
active entity, with a program counter specifying the next instruction to execute and a set of associated
resources.
A program becomes a process when an executable file is loaded into memory.
Two common techniques for loading executable files are double-clicking an icon representing the executable file
and entering the name of the executable file on the command line
PROCESS STATE / PROCESS LIFE CYCLE:
It is important to realize that only one process can be running on any processor at any instant. Many
processes may be ready and waiting,
The OS maintains a separate queue for each of the process states and PCBs of all processes in
the same execution state are placed in the same queue.
When the state of a process is changed, its PCB is unlinked from its current queue and moved to
its new state queue.
Process migration between the various queues:
o Job queue
o Ready queue
o Device queues
The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.).
The OS scheduler determines how to move processes between the ready and run queues which can
only have one entry per processor core on the system; in the above diagram, it has been merged with the
CPU.
SCHEDULERS:
Schedulers are special system software which handles the process scheduling in various ways.
Their main task is to select the jobs to be submitted into the system and to decide which process to
run.
Schedulers are of three types –
o Long-Term Scheduler
o Short-Term Scheduler
o Medium-Term Scheduler
LONG TERM SCHEDULER:
o It is also called a job scheduler.
o A long-term scheduler determines which programs are admitted to the system for processing.
o It selects processes from the queue and loads them into memory for execution.
o Process loads into the memory for CPU scheduling.
o The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O
bound and processor bound.
o It also controls the degree of multiprogramming. If the degree of multiprogramming is stable, then
the average rate of process creation must be equal to the average departure rate of processes leaving the
system.
CONTEXT SWITCH:
A context switch is the mechanism to store and restore the state or context of a CPU in Process
Control block so that a process execution can be resumed from the same point at a later time.
Switching the CPU to another process requires performing a state save of the current process and a state restore of
a different process. This task is known as Context Switching.
When a context switch occurs, the kernel saves the context of the old process in its PCB and loads the saved
context of the new process scheduled to run.
Using this technique, a context switcher enables multiple processes to share a single CPU.
Context switching is an essential part of a multitasking operating system features.
Context switches are computationally intensive since register and memory state must be saved and
restored.
To avoid the amount of context switching time, some hardware systems employ two or more
sets of processor registers.
When the process is switched, the following information is stored for later use.
o Program Counter
o Scheduling information
o Base and limit register value
o Currently used register
o Changed State
o I/O State information
o Accounting information
PROCESS CREATION:
Parent process creates children processes, which, in turn create other processes, forming a tree of
processes.
Each of these new processes may in turn create other processes, forming a tree of processes.
When a process creates a subprocess, that subprocess may be able to obtain its resources directly
from the operating system, or it may be constrained to a subset of the resources of the parent process.
When a process creates a new process, two possibilities exist in terms of execution:
o The parent continues to execute concurrently with its children.
o The parent waits until some or all of its children have terminated.
CPU SCHEDULING
CPU scheduling is a process which allows one process to use the CPU while the execution of another
process is on hold(in waiting state) due to unavailability of any resource like I/O etc, thereby making
full use of CPU
Whenever the CPU becomes idle, the operating system must select one of the processes in the ready
queue to be executed.
The selection process is carried out by the short-term scheduler (or CPU scheduler).
o In a real system, it should range from 40 percent (for a lightly loaded system) to 90 percent (for a
heavily used system).
THROUGHPUT
o It is the total number of processes completed per unit time or rather say total amount of work done in
a unit of time. This may range from 10/second to 1/hour depending on the specific processes.
TURNAROUND TIME
o It is the amount of time taken to execute a particular process, i.e. The interval from time of
submission of the process to the time of completion of the process(Wall clock time).
WAITING TIME
o The sum of the periods spent waiting in the ready queue amount of time a process has been waiting
in the ready queue to acquire get control on the CPU.
LOAD AVERAGE
o It is the average number of processes residing in the ready queue waiting for their turn to get into the
CPU.
RESPONSE TIME
o Amount of time it takes from when a request was submitted until the first response is produced.
Remember, it is the time till the first response and not the completion of process execution (final
response).
SCHEDULING ALGORITHMS:
Non-preemptive scheduling allows a process to hold the CPU until it terminates or enters a waiting
state, preventing interruption by higher-priority tasks. In contrast, preemptive scheduling allows the
operating system to interrupt a currently running process to allocate the CPU to a higher-priority or
more urgent task. Non-preemptive is simpler with lower overhead, while preemptive offers better
responsiveness and is used in modern operating systems.
-*