Unit III Ssos Notes
Unit III Ssos Notes
OPERATING SYSTEM
An operating system (OS) is system software. It manages computer
hardware and software resources. It provides common services for computer
programs. Time-sharing operating systems schedule tasks for efficient use of the
system. It may also include accounting software for cost allocation of processor
time, mass storage, printing, and other resources.
The operating system acts as an intermediary between programs and the computer
hardware. The application code is usually executed directly by the hardware. It is
frequently making system calls to an OS function or is interrupted by it. Operating
systems are found on many devices that contain a computer – from cellular
phones and video game consoles to web servers and supercomputers. For hardware
functions such as input and output and memory allocation.
A process is a program at the time of execution. The process is more than the program
code. It includes the program counter, the process stack, and the content of the process
register, etc. The purpose of the process stack is to store temporary data, such as
subroutine parameters, return address and temporary variables.
PROCESS STATES
Many processes can be running in any processor at any time. But many processes may
be in ready queue waiting for states. Consider the figure below depicts the state
diagram of the process states.
In a uniprocessor system only one process may be running at a time. It several may be
ready and several blocked. The operating system maintains a ready list of ready
processes and a blocked list of blocked processes. The ready list is maintained in
priority order. The next process to receive a processor is the first one in the list (i.e.,
the process with the highest priority). The blocked list is typically unordered -
processes do not become unblocked (i.e., ready) in priority order. Unblock in the order
in which the events they are waiting for occur.
When a user runs a program, processes are created and inserted into the ready list. A
process moves toward the head of the list as other processes complete their turns using
a processor. When a process reaches the head of the list, a processor becomes available,
that process is given a processor.
New to Ready
The operating system creates a process. And prepares the process to be executed by,
then the operating system moves the process into the ready queue.
Ready to Running
When it is time to select a process to run, the operating system selects one of the jobs
for the ready queue and move the processes from the ready state to the running state.
It is said to make a state transition from the ready state to the running state. The act of
assigning a processor to the first process on the ready list is called dispatching. It is
performed by a system entity called the dispatcher. The state transition is,
Running to Terminated
When the execution of a process has completed then the operating system terminates
that process from running state. Sometimes the operating system terminates the
processes for some other reasons also include time limit exceeded, memory
unavailable access violation, protection error, I/O failure, data misuse and so on.
Running to Ready
When the time slot for the processor expires or if the processor receives an interrupt
signal, then the operating system shifts the running process to the ready state.
Processes that are in the ready or running states are said to be awake. To prevent any
one process from monopolizing (controlling) the system, either accidentally or
maliciously the operating system sets a hardware interrupting clock (also called an
interval timer) to allow a process to run for a specific time interval or quantum. The
state transition is,
For example, process P1 is being executed by the processor, at that time processor, P2
generates an interrupt signal to the processor. Then the processor compares the
priorities of process P1 and P2. If P1>P2 then the processor continues executing P1.
Otherwise, the processor switches to process P2, and process P1 is moved to the ready
state.
Running to Waiting
A process is put into the waiting state if the process needs an event to occur, or an I/O
device is to read. The operating system does not provide the I/O or event immediately
then the process is moved to the waiting state by the operating system.
Waiting to Ready
A process in the blocked state is moved to the ready state when the event for which it
has been waiting occurs.
For example, a process is in running state needs an I/O device, then the process
moved to wait or blocked state. When the I/O device is provided by the operating
system, the process moved to the ready state from waiting or blocked state.
Running to Block
Block to Ready
The only other allowable state transition in three-state model occurs when an I/O
operation (or some other event the process is waiting for) completes. In this case, the
operating system transitions the process from the blocked to the ready state. The state
transition is,
INTERRUPT
Interrupts enable software to respond to signals from hardware. The operating system
may specify a set of instructions, called an interrupt handler to be executed in response
to each type of interrupt. This allows the operating system to gain control of the
processor to manage system resources. Interrupt is called a trap. Synchronous with
the operation of the process. For example, dividing by zero or referencing protected
memory. Interrupts may also be caused by some event that is unrelated to a process's
current instruction. Asynchronous with the operation of the process. For example, the
keyboard generates an interrupt when a user presses a key. The mouse generates an
interrupt when it moves or when one of its buttons is pressed. Interrupts provide a
low-overhead means of gaining the attention of a processor. Polling is an alternative
approach for interrupts. Processor repeatedly requests the status of each device.
Increases in overhead as the complexity of the system increases.
A simple example microwave oven. A chef may either set a timer to expire after an
appropriate number of minutes (the timer sounding after this interval interrupts the
chef) The chef may regularly peek through the oven's glass door and watch as the
roast cooks (this kind of regular monitoring is an example of polling).
Interrupt processing
Handling Interrupts
1. The interrupt line, an electrical connection between the mainboard and a processor.
It becomes active—devices such as timers, peripheral cards and controllers send
signals that activate. The interrupt line to inform a processor that an event has
occurred (e.g., a period of time has passed or an I/O request has completed). Most
processors contain an interrupt controller that orders interrupts according to their
priority so that important interrupts are serviced first. Other interrupts are queued
until all higher-priority interrupts have been serviced.
2. After the interrupt line becomes active, the processor completes execution of the
current instruction, then pauses the execution of the current process. To pause process
execution, the processor must save enough information. The process can be resumed
at the correct place and with the correct register information.
3. The processor then passes control to the appropriate interrupt handler. Each type
of interrupt is assigned a unique value that the processor uses as an index into the
interrupt vector, which is an array of pointers to interrupt handlers. The interrupt
vector is located in memory that processes cannot access, so that processes cannot
modify its contents.
4. The interrupt handler performs appropriate actions based on the type of interrupt.
5. After the interrupt handler completes, the state of the interrupted process is
restored.
6. The interrupted process (or some other "next process") executes. It is the
responsibility of the operating system to determine whether the interrupted process
or some other "next process" executes.
Interrupt classes
These are initiated by a running process that executes the SVC instruction. It is a user-
generated request for a particular system service such as performing input/output. It
helps keep the operating system secure from the users. A user may not arbitrarily
enter the operating system. The user must request a service through as SVC.
I/O interrupts
These are initiated by the input/output hardware. They signal to the CPU that the
status of a device has changed. I/O interrupts are caused when an I/O operation
completes, when an I/O error occurs.
External interrupts
Restart interrupts
These occur when the operator presses the console’s restart button. When a restart
SIGP (Signal Processor) instruction arrives from another processor on a
multiprocessor system.
These are caused by a wide range of problems. It may occur as a program’s machine
language instructions are executed. Example, division by zero, arithmetic overflow or
underflow. Data in wrong format attempt to reference a memory location beyond the
limits of real storage memory.
STORAGE MANAGEMENT
locations will be assigned. It tracks when memory is freed or unallocated and updates
the status.
Storage Hierarchy
Programs and data must be in main memory before the system can execute or
reference them. Those that the system does not need immediately may be kept in
secondary storage until needed, then brought into main memory for execution or
reference.
Secondary storage media, such as tape or disk, are generally far less costly per bit than
main memory and have much greater capacity. Main storage may generally be
accessed much faster than secondary storage. The memory hierarchy contains levels
characterized by the speed and cost of memory in each level. Systems move programs
and data back and forth between the various levels. The cache is a high-speed storage
that is much faster than main storage.
Cache memory imposes one more level of data transfer on the system. Cache storage
is extremely expensive compared with main storage. Programs in main memory are
transferred to the cache before being executed—executing programs from cache is
much faster than from main memory.
Memory management strategies are designed to obtain the best possible use of main
memory.
1. Fetch strategies
2. Placement strategies
3. Replacement strategies
Fetch strategies
It determines when to move the next piece of a program or data to main memory from
secondary storage.
Demand fetch strategy: The system places the next piece of program or data in main
memory when a running program references it. Designers believed that because
cannot in general predict the paths of execution that programs will take, the overhead
involved in making guesses would far exceed expected benefits.
Placement strategies
It determines where in main memory the system should place incoming program or
data pieces. Consider first-fit, best-fit, and worst-fit memory placement strategies.
program and data can be divided into fixed-size pieces called pages. It can be placed
in any available page frame.
Replacement strategies
When memory is too full to accommodate a new program, the system must remove
some (or all) of a program or data that currently resides in memory. The system's
replacement strategy determines which piece to remove.
The operating system and the user’s processes both must be accommodated in the
main memory. The main memory is divided into two partitions.
In usual conditions, the several user processes must reside in the memory at the same
time. It is important to consider the allocation of memory to the processes. The
Contiguous memory allocation is one of the methods of memory allocation. In
contiguous memory allocation, when a process requests for the memory. A single
contiguous section of memory blocks is assigned to the process according to its
requirement.
Paging and segmentation are the two ways which allow a process physical address
space to be non-contiguous. In non-contiguous memory allocation, the process is
divided into blocks (pages or segments) which are placed into the different area of
memory space according to the availability of the memory. The non-contiguous
memory allocation has an advantage of reducing memory wastage but,
it increases the overheads of address translation. The process is placed in a different
location in memory, it slows the execution of the memory because time is consumed
in address translation.
Contiguous versus Non-contiguous Storage allocation
The memory organization for a typical single-user contiguous memory allocation system
Overlay Structure
The programmer divides the program into logical sections. When the program does
not need the memory for one section. The system can replace some or all of it with the
memory for a needed section. Overlays enable programmers to "extend" main
memory. However, manual overlay requires careful and time-consuming planning.
The programmer often must have detailed knowledge of the system's memory
organization. A program with a sophisticated overlay structure can be difficult to
modify. Indeed, as programs grew in complexity, by some estimates as much as 40
percent of programming expense were for organizing overlays. It became clear that
the operating system needed to insulate the programmer from complex memory
management tasks such as overlays.
Protection in a Single-User System
A process can interfere with the operating system's memory - either intentionally or
inadvertently (mistake) -by replacing some or all of its memory contents with other
data. If it destroys the operating system, then the process cannot proceed. If the
process attempts to access memory occupied by the operating system.
Boundary register
The user can detect the problem, terminate execution, possibly fix the problem and re-
launch the program. Protection in single-user contiguous memory allocation systems
can be implemented with a single boundary register built into the processor.
The boundary register contains the memory address at which the user's program
begins. Each time a process references a memory address, the system determines if the
request is for an address greater than or equal to that stored in the boundary register.
The hardware that checks boundary addresses operates quickly to avoid slowing
instruction execution. The single boundary register represents a simple protection
mechanism.
Early single-user real memory systems were dedicated to one job for more than the
job's execution time. Jobs generally required considerable setup time during which the
operating system was loaded tapes and disk packs were mounted. When jobs
completed, they required considerable teardown time as tapes and disk packs were
removed. Designers realized that if they could automate various aspects of job-to-job
transition. It could reduce considerably the amount of time wasted between jobs. This
led to the development of batch-processing systems.
In single stream batch processing, jobs are grouped in batches by loading them
consecutively onto tape or disk. A job stream processor reads the job control language
statements and facilitates the setup of the next job. Batch-processing systems greatly
improved resource utilization and helped demonstrate the real value of operating
systems and intensive resource management. Single-stream batch-processing systems
were the state of the art in the early 1960s.
The main memory has to accommodate both the operating system and user space.
Now, here the user space has to accommodate various user processes. We also want
these several user processes must reside in the main memory at the same time.
Fixed/Static Partitioning
Variable/Dynamic Partitioning
Simple/Basic Paging
Simple/Basic Segmentation
Advantage of Multiprogramming
It is necessary for several jobs to reside in the computer’s main storage at once. When
one job requests input/output, the CPU may be immediately switched to another and
may do calculations without delay. Multiprogramming requires considerably more
storage than a single user system. The improved resource use for the CPU. The
peripheral devices more than justifies the expense of additional storage.
Fixed partition multiprogramming in which main storage was divided into a number
of fixed-size partitions. Each partition holds a single job. The CPU was switched
rapidly between users to create the illusion of simultaneity.
Jobs were translated with absolute assemblers and compilers to run only in a specific
partition. Job was ready to run and its partition was occupied. Then that job had to
wait, even if other partitions were available. This resulted in waste of the storage
resource. But the OS was relatively straightforward to implement.
Memory waste under fixed partition multiprogramming with absolute translation and loading
System designers found fixed partitions too respective. It decided that an obvious
improvement, to allow jobs to occupy as much storage needed. No fixed boundaries
would be observed. Instead, jobs would be given as much storage as they required is
called variable partition multiprogramming.
In variable partition multiprogramming, the waste does not become obvious until jobs
start to finish. Leave holes in the main storage. These holes can be used for other jobs.
These remaining holes get smaller eventually becoming too small to hold new jobs.
Coalescing holes
Storage compaction
Coalescing holes
❖ An additional hole.
❖ A single hole reflecting the merger of the existing hole.
❖ New adjacent hole.
The process of merging adjacent holes to form a single larger hole in called coalescing.
Storage compaction
When a job requires a certain amount of main storage no individual hole is large
enough to hold the job. Even though the sum of all the holes is larger than the storage
needed by the new job. The technique of storage compaction involves moving all
occupied areas of storage to one end or the other of main storage. Rearranges memory
into a single contiguous block free space. A single contiguous block of occupied space.
It is also referred as burping the storage or garbage collection.
This method keeps the free/busy list of jobs organized by memory location, low-
ordered to high-ordered memory. In this method, first job claims the first available
memory with space more than or equal to its size. The operating system doesn’t search
for appropriate partition but just allocate the job to the nearest memory partition
available with sufficient size.
This method keeps the free/busy list in order by size – smallest to largest. In this
method, the operating system first searches the whole of the memory according to the
size of the given job and allocates it to the closest-fitting free partition in the memory,
making it able to use memory efficiently. Here the jobs are in the order from smallest
job to largest job.