Os All
Os All
• An Operating System is a group of programs that allow a user to control and communicate with a
computer.
• It manages the hardware, software, memory, and processes of the computer. • It is the most
important software that runs on a computer.
• Normally, a number of computer programs operate concurrently, requiring access to the computer's
processor (CPU), memory, and storage.
• Computer System
- Software (programs)
• Operating System
- Controls every file, device, section of main memory and nanosecond of processing time.
• Microsoft Windows
• macOS
• Linux
• Android
• iOS
• 5 Essential Managers of OS
1. Memory Manager
2. Processor Manager
3. Device Manager
4. File Manager
5. Network Manager
Manager Tasks
• Enforce the system policies that determines who gets what, when, and how.
Mainframe
• Required an air-conditioned room about 18 feet square. • The CPU was 5 feet high and 6 feet wide.
MINI Computer
• Compared to mainframe
• Example: Digital Equipment Corp’s (early 1970) Price: less than $18,000
SUPER Computer
• Massive machine that handles massive computations • It was developed primarily for government
applications • For military operations and weather forecasting • Example: Cray supercomputer
- 6 to 1,000 processors
• Uses:
- Scientific research
MICRO Computer
• Example: microcomputers by Tandy Corporation and Apple Computer, Inc. - Very little memory
(compared by today’ standards)
• Microcomputer’s distinguishing
characteristic
- Single-user status
Workstations
• Networked together
- Applications
Servers
• Powerful computers that provide specialized services to other computers on client/server networks.
• Examples:
- Print servers
- Internet servers
- Mail servers
Chapter 2
Types of Operating System
• Operating Systems for large and small computers fall into five categories distinguished by response
time and how data is entered into the system: batch, interactive, real-time, hybrid, and embedded
systems.
• Batch Systems
- Batch systems date from earliest computers, when they relied on stacks of punched cards or reels of
magnetic tape for input. - Jobs were entered by assembling the cards into a deck and running the entire
deck of cards through a card reader as a group – a batch.
- The efficiency of a batch system is measured in throughput – the number of jobs completed in a given
amount of time
(500 jobs/hour).
• Interactive Systems
- Give a faster turnaround than batch systems but are slower than the real-time systems.
- They were introduced to satisfy the demands of users who needed fast turnaround when debugging
their programs.
- If provides immediate feedback to the user and response time can be measured in fractions of a
second.
• Real-time Systems
- Used in time-critical environments where reliability is key and data must be processed within a strict
time limit.
- The time limit need not be ultra-fast (though it often is), but system response time must meet the
deadline or risk significant
consequences.
- These systems also need to provide contingencies to fail gracefully – that it preserve as much of the
system’s capabilities and data is possible to facilitate recovery.
- Hard real-time system – missing a deadline can cause the whole system to fail.
- Soft real-time system - missing a deadline only causes slower or weaker performance, not a full failure.
• Hybrid Systems
- Accepts and runs batch programs in the background when the interactive load is light.
- It takes advantage of the free time between high-demand usage of the system and low-demand times.
• Embedded Systems
- Computers placed inside other products to add features and capabilities. - For example, you find
embedded computers in household appliances, automobiles, digital music players, elevators, and
pacemakers.
- Each one is designated to perform a set of specific programs, which are not interchangeable among
systems.
- This permits the designers to make the operating system more efficient and take advantage of the
computer’s limited resources, such as memory, to their maximum.
- Typical program included every instruction needed by computer to perform the tasks requested.
- CPU processed data and performed calculations for fraction of available time.
- Developed to meet the needs of new markets – government and business researchers.
- Computer operators were hired to facilitate machine operations. - Concept of job scheduling: group
together programs with similar requirements.
- Job scheduling introduced the need for control cards, which defined the exact nature of each program
and its requirements. - First use of a job control language.
- Speed of I/O increased
- Blocking
- Buffering
- Spooling
- Faster CPUs
- Speed still caused problems when they interacted with printers and other I/O devices that ran at
slower speeds.
- The solution was multiprogramming, which introduced the concept of loading many programs at one
time and sharing the attention of a single CPU.
- Active multiprogramming
- Passive multiprogramming
- the operating system didn’t control the interrupts but waited for each job and an execution sequence.
• 1970s
- Main memory physical capacity limitations
- Became a popular tool because it organized data in an integrated manner, minimized redundancy, and
simplified updating and access of data.
- Programs started using English-like words, modular structures, and standard operations
• 1980s
- Cost/performance ratio improvement of computer components. - Hardware was more flexible, with
logical functions built on easily replaceable circuit boards.
- Firmware, a word used to indicate that a program is permanently held in read-only memory (ROM).
- More complex languages were designed to coordinate the activities of the multiple processors
servicing a single job.
• 1990s
- The overwhelming demand for Internet capability sparked the proliferation of networking capability.
- The World Wide Web by Tim Berners-Lee made the internet accessible by computer users worldwide.
• 2000s
- Multimedia applications
- Client/server computing
Object-Oriented Design
• An important area of research that resulted in substantial efficiencies was that of the system
architecture of operating systems.
• The way their components are programmed and organized, specifically the use of object-oriented
design and the reorganization of the operating system’s nucleus, the kernel.
• The kernel is the part of the operating system that resides in memory at all times, performs the most
essential operating system tasks, and is protected by hardware from user tampering.
Early OS vs Object-Oriented OS
Chapter 3
Memory Management
• Resources (instructions and data) that the CPUs can immediately access are kept in the main memory.
• However, controlling the main memory is a challenging task that requires many approaches over time.
• Access Memory
• Core Memory
• Primary Storage
Early Memory Allocation Schemes
2) Fixed partitions
3) Dynamic partitions
• This scheme requires a minimal amount of work done by the operating system’s Memory Manager.
• Program was loaded in its entirety into memory and allocated as much contiguous space in memory
as needed.
Fixed Partition
• Static partitions
• Permits multiprogramming
• Partition sizes remain static unless and until computer system is shut down, reconfigured, and
restarted.
• Requires:
Fixed Partition
Table 1: A simplified fixed-partition memory table with the free partition shaded
Fixed Partition
Dynamic Partition
• Memory is divided into variable-sized partitions based on the size of the process/jobs being executed.
• Jobs are given only as much memory as they request when they are loaded.
partition allocation
• Free partitions are allocated on the following basis/strategies: - First Fit memory allocation:
Job Memo
Num ry
ber Reque
sted
J1 10K
J2 20K
J3 30K
J4 10K
Figure 4: Example
of
Job Memory
Number Requeste
d
J1 10K
J2 20K
J3 30K
J4 10K
Figure 5: Example
of
Deallocation
• Memory Manager relocates programs to gather together all of the empty blocks and compact them to
make one block of memory, large enough to accommodate some or all of the jobs waiting to get in
Virtual Memory
• A storage method that gives the user the impression that their main memory is quite large.
• By giving the user the impression that there is memory available to load the process, this approach
allows them to load larger size programs than the primary memory that is accessible.
• By doing this, the level of multiprogramming will be enhanced, which will increase CPU consumption.
Paging in OS
• Paging is storage mechanism.
• The processes in the memory are divided into small equal blocks called pages.
• It also divides the physical memory into the same size pieces called frames. • Each of the pages
contains the process which is retrieved into main memory and is stored in one frame of memory.
• Note: it is very important to have pages and frames which are of equal sizes which are very useful for
mapping and complete utilization of memory.
Demand Paging
• The pages of the processes are stored in the secondary memory and the page is brought to the main
memory when required.
• The pages are brought to the main memory when required by the Page Replacement Algorithms.
• The process of calling the pages to main memory from secondary memory upon demand/request.
• In an Operating System that uses paging for memory management, a page replacement algorithm is
needed to decide which page needs to be replaced when a new page comes in.
➢ Page Fault
- occurs when a program tries to access a memory page that is not present in the memory.
➢ Page Hit
- occurs when a program tries to access a memory page that is already present in the memory.
- In FIFO page replacement algorithm, the policy is to remove the pages that have been in memory the
longest.
First In First Out (FIFO) Algorithm
Page Fault = 9
Page Hit = 2
- In this algorithm, page will be replaced which is least recently used. - Page replacement policy swaps
out the pages that show the least amount of recent activity, figuring that these pages are the least likely
to be used again in the immediate future.
Fault
Chapter 4
Processor Management
• If you were assembling some IKEA furniture, and following the step-by-step guide of 20 steps.
• Imagine you did step 1, then step 2, then step 3, suddenly the doorbell rang, and you are interrupted.
• You would stop what you are doing and deal with whoever is at the door. • Then you would return to
the assembly, check what step you were on, and then continue on from there (step 4).
Processor Management
• A “Process” is the name we give to a program when it is running in memory. - A Program is a compiled
set of instructions that are stored in an executable file.
- A Process is the instance of this executable file that the operating system runs, along with its
associated resources and current state of execution (e.g., memory allocation)
• The Processor Manager is made up of two sub-managers: 1. Job Scheduler (High level scheduler)
Job Scheduler
• When the operating systems is presented with a queue of jobs or processes to run, the Job Scheduler
has the task of deciding which order to run the jobs in.
• The Job Scheduler wants to ensure that all components of the operating system are busy, and there is
no component that is idle.
PROGRAM PrintValue:
BEGIN
Input A;
Input B;
C = A + B;
D = A – B;
• We'll call jobs that are CPU-bound Batch Jobs, and we’ll call jobs that have a lot of I/O operations
Interactive Jobs.
• So, in this case the Job Scheduler wants to balance the jobs coming in, so that the components of the
operating system are all kept busy. • If we don’t change the order of job, the CPU will be very busy, but
the I/O component will be idle, and then vice versa.
• Every process has a field that records their current status, called the Process Control Block (PCB).
• When the process is first passed to the Job Scheduler from the operating system, its status is always
set as HOLD. • When the Job Scheduler passes the process onto the Process Scheduler, its status is
always changed to READY.
Process Scheduler
• Assigns the CPU to execute processes of those jobs placed on ready queue by Job Scheduler.
• After a job has been placed on the READY queue by Job Scheduler, Process Scheduler takes over:
- Determines which jobs will get CPU, when, and for how long. - Decides when processing should be
interrupted.
- Determines queues job should be moved to during execution. - Recognizes when a job has concluded
and should be terminated.
• Removes active jobs from memory to reduce degree of multiprogramming and allows jobs to be
completed faster.
• When the jobs moves through the system and makes progress, it changes its states from HOLD to
FINISH.
• When the job is being processed by the job manager and the process manager, it is always in one of
these 5 states: 1. HOLD
2. READY
3. RUNNING
4. WAITING
5. FINISHED
1) HOLD - When a user submits a job and it accepts the job, the job is put on HOLD and placed in a
queue.
2) READY - A job is in READY state when it’s ready to run and waiting for the CPU.
4) WAITING - When a job is in WAITING state, it means that the job can’t continue until a specified I/O
operation is done or a resource is allocated.
5) FINISHED - When a job is in FINISHED state, it means that the job is done and the output will be
returned to the user.
Process States
1. HOLD to READY is done by the job scheduler according to availability of main memory space and
some specific policies.
2. READY to RUNNING is done by the process scheduler (to decide which job will be done first)
according to some algorithms (e.g. FCFS).
3. RUNNING back to READY is done by process scheduler according to some criterion (e.g. Priority
Interrupt).
4. RUNNING to WAITING is done by process scheduler when some I/O request is encountered in the job
itself or some resource allocation is required.
5. WAITING to READY is done by the process scheduler when the requirements needed by the jobs are
satisfied (I/O request satisfied).
• Process Control Block (PCB) - data structure that contains basic info about the job
- Process identification
- Process state (process status word, register contents, main memory info,
- Accounting (CPU time, total amount of time, I/O operations, number input records read)
- Example, PCBs for every ready job are linked on READY queue; all PCBs for jobs just entering system
are linked on HOLD queue. - Queues must be managed by process scheduling policies and algorithms.
• Before operating system can schedule all jobs in a multiprogramming environment, it must resolve
three limitations of system:
- finite number of resources (such as disk drives, printers, and tape drives)
• Preemptive scheduling policy interrupts processing of a job and transfers the CPU to another job.
- Once a job captures processor and begins execution, it remains in RUNNING state uninterrupted.
Interrupts
• There are instances when a job claims CPU for a very long time before issuing an I/O request.
• Process Scheduler uses a timing mechanism to periodically interrupts running processes when a
predetermined slice of time has expired. - Suspends all activity on the currently running job and
• Scheduling algorithms, schedule processes on the processor in an efficient and effective manner.
✓ Arrival Time (AT): Time at which the process arrives in the ready queue. ✓ Completion Time (CT):
Time at which process completes its execution. ✓ Burst Time (BT): Time required by a process for CPU
execution. ✓ Turn Around Time (TAT): Time Difference between completion time and arrival time. ✓
Waiting Time (WT): Time Difference between start time and arrival time (Non-Preemptive Scheduling
Policy).
- considered to be the simplest of all operating system scheduling algorithms. First come first serve
scheduling algorithm states that the process that requests the CPU first is allocated to the CPU first and
is implemented by using FIFO queue.
Characteristics of FCFS:
✓ Tasks are always executed on a First-come, First-serve concept. ✓ FCFS is easy to implement and use.
✓ This algorithm is not much efficient in performance, and the wait time is quite high.
- also known as shortest job first (SJF), a scheduling algorithm that selects the waiting process with the
smallest burst time to execute next. Can be preemptive or non-preemptive.
Characteristics of SJN:
✓ SJN has the advantage of having a minimum average waiting time among all operating system
scheduling algorithm.
- is the scheduling algorithm where each process is cyclically assigned a fixed time slot. It is the
preemptive version of FCFS Scheduling Algorithm. It generally focuses on the Time-Sharing technique.
Characteristics of RR:
✓ RR is simple, and starvation-free as all processes get the balanced CPU allocation.
✓ One of the most widely used methods in Process Scheduling ✓ Considered preemptive as the
processes are given to the CPU for a very limited time.
Chapter 5
Deadlock
- Deadlock
- Starvation
• A problem where resources needed by some process to finish execution are held by other processes,
which, in turn, are waiting for other resources to become available.
• Case 3: Deadlocks in Dedicated Device Allocation • Case 4: Deadlocks in Multiple Device Allocation •
Case 5: Deadlocks in Spooling
• The spooler accepts output from several users and acts as a temporary storage area for all output
until the printer is ready to accept it.
• Mutual exclusion
- act of allowing only one person (or process) to have access to a step (a dedicated resource)
• Resource Holding
- When two people meet on the stairs and each one holds ground and waits for the other to retreat
• No Preemption
- Each step is dedicated to the climber; it is allocated to the holder for as long as needed.
• Circular Wait
- Each person (or process) involved in the impasse is waiting for another to voluntarily release the step
(or resource) so that at least one will be able to continue on and eventually arrive at the destination.
• Detection
• Prevention
• Avoidance
• Recovery
Detection
• The directed graphs presented earlier in this chapter showed how the existence of a circular wait
indicated a deadlock, so it’s reasonable to conclude that deadlocks can be detected by building
directed resource graphs and looking for cycles.
Prevention
• To prevent a deadlock, the operating system must eliminate one of the four necessary conditions, a
task complicated by the fact that the same condition can’t be eliminated
Avoidance
• Even if the operating system can’t remove one of the conditions for deadlock, it can avoid one if the
system knows ahead of time the sequence of requests associated with each of the active processes.
Recovery
• Once a deadlock has been detected, it must be untangled and the system returned to normal as
quickly as possible.
• There are several recovery algorithms, but they all have one feature in common: They all require at
least one victim, an expendable job, which, when removed from the deadlock, will free the system.
Starvation
• At the opposite end is starvation, the result of conservative allocation of resources where a single job
is prevented from execution because it’s kept waiting for resources that never become available.
Chapter 7
Basic Functions
• Monitoring the status of each device (storage drives, printers, etc.) • Enforcing present policies
- determine which process will get a device and for how long • Allocating the devices
- Job level
Types of Devices
• Dedicated Devices
• Shared Devices
• Virtual Devices
Types of Devices
• Dedicated Devices
- serve that job for the entire time it’s active or until it releases them
• Examples:
- Tape drives
- Printer
- Scanner
- Plotters
• Shared Devices
• Example:
- can be shared by several processes at the same time by interleaving their requests.
• Virtual Devices
- they’re dedicated devices that have been transformed into shared devices.
• Example:
- acts as an interface between the OS, device drivers, and applications attached via USB host.
- One USB host can accommodate up to 127 different devices - Devices can be flash memory, cameras,
scanners, musical keyboards. - Each devices is identified by the USB host controller with a unique
identification number, that allows many devices to exchange data with the computer using the same
USB connection.
Storage Media
• A physical device that receives, stores, and allows users and programs to access electronic data.
• The storage media might be inside a computer or other device or attached to a system externally,
either directly or over a network.
• Example:
- CD ROM, DVD ROM, DAT tape, DLT tape, disk drives, SSD, Flash Drive.
- Direct Access Storage Devices (DASD) - store either sequential or direct access files
Magnetic tape
• Developed for routine secondary storage in early computer systems and features records that are
stored serially, one after other.
• The length of these records is usually determined by the application program and each record can be
identified by its position on the tape. • To access a single record, the tape must be mounted and fast-
forwarded until the desired position is located.
• Let’s consider a hypothetical computer system that uses a reel tape that is 2400 feet long.
Density of the Tape
• Determined by the number of characters that can be recorded per inch, such as (1600 bpi).
• For example, if you had records of 160 characters each, and were storing them on a tape with a
density of 1600 bpi, then you can store 10 records on one inch of tape.
• Records can be stored individually or grouped into blocks: • If the records are stored individually, each
record would need to be separated by a space to indicate its starting and ending places. • If the records
are stored in blocks
- Preceded by a space
- Followed by a space
- Way of grouping the record into blocks before recording them on tape.
- Density of the tape (measured in bpi), multiplied by tape drive speed (transport speed)
Example:
• How long does it take to access a block or record on magnetic tape? - depends on where the record is
located, can be calculated.
• For example, our 2400-foot reel of tape with a tape transport speed of 200 ips can be read without
stopping in approximately 2.5 minutes.
• Therefore, it would take 2.5 minutes to access the last record on the tape. • On the average, then, it
would take 1.25 minutes to access a record. And to access one record after another sequentially would
take as long as it takes to start and stop a tape - which is 0.003 seconds, or 3 milliseconds (ms).
• Access Time
Chapter 7
Storage Media
• Storage media are divided into two groups: ○ Sequential Access Storage Media
- store records sequentially, one after the other ○ Direct Access Storage Devices (DASD)
- store either sequential or direct access files • There are vast differences in their speed and
shareability.
- Optical discs
- Flash memory
• Although the variance in DASD access times isn’t as wide as with magnetic tape, the location of the
specific record still has a direct effect on the amount of time required to access it.
Fixed-Head Magnetic Disk Storage
• Looks like CD or DVD covered with magnetic film that has been formatted.
• Data is recorded serially on each track by the fixed read/write head position over it.
importance
• High costs
○ movable disk
• Have one read/write head that floats over each surface of each disk. • Disk can be a single platter or
part of a disk pack/stack of magnetic platters.
Each platter has two surfaces for recording, and each surface is formatted with a specific number of
concentric tracks where the data is recorded. Each track on each surface is numbered:
Track 0 identifies the outermost concentric circle on each surface; the highest-numbered track is in the
center
The arm moves two read/write heads between each pair of surfaces: 1 surface above and 1 surface
below.
The arm moves all of the heads in unison, so if one head is on Track 36, then all of the heads are on
Track 36 - in other words, they’re all positioned on the same track but on their respective surfaces
creating a virtual cylinder.
Movable-Head Magnetic Disk Storage
Optical Disc Storage
• Was made possible by developments in laser technology. • Single spiraling track of same-sized
sectors.
Optical disc consists of a single spiraling track of same-sized sectors running from the center to the
rimof the disc.
• To put data on an optical disc, a high-intensity laser beam burns indentations on the disc that are
called pits.
• These pits, which represent 0s, contrast with the unburned flat areas, called lands, which represent
1s.
• The first sectors are located in the center of the disc the laser moves outward reading each sector in
turn.
Optical Disc vs Magnetic Disk
• Among the many differences between an optical disc and a magnetic disk is the design of the disc
track and sectors.
• A magnetic disk, which consists of concentric tracks of sectors, spins at a constant speed—this is
called constant angular velocity (CAV). • Because the sectors at the outside of the disk spin faster past
the read/write head than the inner sectors, outside sectors are much larger than sectors located near
the center of the disk.
• On the other hand, an optical disc consists of a single spiraling track of same-sized sectors running
from the center to the rim of the disc. • This single track also has sectors, but all sectors are the same
size regardless of their locations on the disc.
• The disc drive adjusts the speed of the disc’s spin to compensate for the sector’s location on the disc
—this is called constant linear velocity (CLV).
• A nonvolatile removable medium that emulates random access memory, but, unlike RAM, stores data
securely even when it’s removed from its power source.
• Historically, flash memory was primarily used to store startup (boot up) information for computers,
but is now used to store data for cell phones, mobile devices, music players, cameras, and more.
• The bits can be erased only by applying the flash to a large block of memory with each flash erasure,
the block becomes less stable.
• In time (after 10,000 to 1,000,000 uses), a flash memory device will no longer reliably store data.
• Examples:
- SSDs
- Memory cards,
• File Manager is also called the File Management System and is the software responsible for:
File Concept
• Files are the building blocks of any operating system. Permanent storage of information & data.
• OS is not interested in what information is stored in file. OS maps files with physical devices.
• User prepare a program (file), File represent program and data. The output of program is called
executable file.
• File access mechanism refers to the manner in which the records of a file may be accessed.
• Is a method of accessing data sequentially/one record at a time by starting from the beginning of the
file to its end.
• This access method is the most primitive and straightforward method of accessing files.
• Disadvantage: slow and inefficient for random access operations or when working with large files
• Allows users to access data directly from any location within the file without the need to
read/writeall the records that come before it.
• Disadvantage: more complex and difficult to implement and use than sequential file access.
Access Methods: Indexed File Access
• Is a method that incorporates the benefits of both sequential and direct file access.
• Creating an index file that maps logical keys or data elements to their corresponding physical
addresses within the file.
• Index is searched sequentially and its pointer is used to access the file directly.
• Advantage: speed and efficiency for random and sequential access operations.
• Disadvantage: requires additional storage for the index, increase the cost and complexity of the
system.
File types
• File type refers to the ability of the operating system to distinguish different types of file such as text
files, source files, and binary files etc.
• Operating system like MS-DOS and UNIX have the following types of files:
• Ordinary files
• Directory files
• Special files
• These are the files that contains user information. • These may have text, databases or executable
program. • The user can apply various operations on such files like - add, modify, delete or even remove
the entire file.
• Directory files contains list of file and other related information to those files.
• Also known as “folders” in other operating systems. • Folders that holds and organize multiple files.
- disks, terminals, printers, networks, tape drive etc. • These files are of two types:
• Character special files − data is handled character by character as in case of terminals or printers.
• Block special files − data is handled in blocks as in the case of disks and tapes.
File Operations
• Delete: File must has to be deleted when it is no longer needed just to free up the disk space.
• Open: The process must open the file before using it.
• Close: The file must be closed to free up the internal table space, when all the accesses are finished
and the attributes and the disk addresses are no longer needed.
• Read: The file read operation is performed just to read the data that are stored in the required file.
File Operations
• Write: The file write operation is used to write the data to the file, again, generally at the current
position.
• Append: The file append operation is same as the file write operation except that the file append
operation only add the data at the end of the file.
• Seek: For random access files, a method is needed just to specify from where to take the data.
Therefore, the file seek operation performs this task.
• Rename: The file rename operation is used to change the name of the existing file.
Directory Structure
• Directory
is a list of files that stores all the related information about the file it hold with the contents. Directory is
a list of files.
Each entry of a directory define a file information like a file name, type, its version number, size ,owner
of file, access rights, date of creation and date of last backup.
• Types:
- in a single level directory system, all the files are placed in one directory
Directory Structure
- in the two-level directory system, the system maintains a master block that has one entry for each
user.
3. Tree-structured directory structure
- in the tree-structured directory, the directory themselves are files. This files to the possibility of having
sub-directories that can contain files and sub-subdirectories
Data Compression
• A reduction in the amount of bits required to represent data is known as data compression.
• Compressing data can save storage capacity, speed up file transfer and decrease costs for storage
hardware and network bandwidth.
How compression works
• Compression is performed by a program that uses a formula or algorithm to determine how to shrink
the size of the data. • For instance, an algorithm may represent a string of bits -- or 0s and 1s -- with a
smaller string of 0s and 1s by using a dictionary for the conversion between them.
• When information is sent or received via the internet, larger files -- either singly or with others as part
of an archive file -- may be transmitted in a ZIP, GZIP or other compressed format.