Final Exam
Final Exam
2024
1
EXE.(1)
Consider the following set of processes, with the length of the CPU burst time given in milliseconds:
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.
a. a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling
algorithms: FCFS, SJF, non-preemptive priority (a larger priority number implies a higher priority), and RR
(quantum = 2).
b. What is the waiting time of each process for each of these scheduling algorithms?
Chapter 5
Background
Processes can execute concurrently
• May be interrupted at any time, partially completing execution
Concurrent access to shared data may result in data inconsistency
Maintaining data consistency requires mechanisms to ensure the orderly
execution of cooperating processes
Processes within a system may be independent or cooperating
Cooperating process can affect or be affected by other processes, including
sharing data
Race Condition
Race condition: The situation where several processes access – and
manipulate shared data concurrently. The final value of the shared data
depends upon which process finishes last.
To prevent race conditions, concurrent processes must be synchronized.
Critical Section Problem
Simplest and most useful model requires that each process declare the maximum number
of resources of each type that it may need
The deadlock-avoidance algorithm dynamically examines the resource-allocation state to
ensure that there can never be a circular-wait condition
Resource-allocation state is defined by the number of available and allocated resources,
and the maximum demands of the processes
Deadlock Detection
Allow system to enter deadlock state
Detection algorithm
Recovery scheme
Recovery from Deadlock: Resource Preemption
We successively preempt some resources from processes and give these resources to other
processes until the deadlock cycle is broken. Three issues need to be addressed:
Rollback – return to some safe state, restart process for that state
Starvation – same process may always be picked as victim, include number of rollback in
cost factor
Questions
?What is the difference between Synchronization and preventing deadlock -1
A deadlock prevention method assures that at least one of the four deadlock conditions never
occurs. In contrast, the deadlock avoidance mechanism prevents the system from coming to an
.unsafe state
Chapter 7
Background
Program must be brought into memory (from disk) and placed within a
process for it to be run.
Input queue – collection of processes on the disk that are waiting to be
brought into memory to run the program.
User programs go through several steps before being run.
Main memory and registers are only storage CPU can access directly
Memory unit only sees a stream of:
addresses + read requests, or
address + data and write requests
Binding of Instructions and Data to Memory
Address binding of instructions and data to memory addresses can happen at
three different stages
• Compile time: If memory location known a priori, absolute code can be
generated; must recompile code if starting location changes
• Load time: Must generate relocatable code if memory location is not
known at compile time
• Execution time: Binding delayed until run time if the process can be moved
during its execution from one memory segment to another
Need hardware support for address maps (e.g., base and limit registers)
Logical vs. Physical Address Space
The concept of a logical address space that is bound to a separate physical
address space is central to proper memory management
• Logical address – generated by the CPU; also referred to as virtual
address
• Physical address – address seen by the memory unit
Dynamic loading and dynamic linking are both techniques used in operating
systems to manage and execute programs, but they serve different purposes.
Dynamic loading is about loading a program into memory at runtime, while
dynamic linking is about linking a program with external libraries or
modules at runtime rather than at compile time.
Both techniques contribute to efficient memory usage and flexible program
execution in an operating system.
Swapping
A process can be swapped temporarily out of memory to a backing store, and
then brought back into memory for continued execution.
Backing store – fast disk large enough to accommodate copies of all memory
images for all users; must provide direct access to these memory images.
Roll out, roll in – swapping variant used for priority-based scheduling
algorithms; lower-priority process is swapped out so higher-priority process
can be loaded and executed.
Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped.
Modified versions of swapping are found on many systems, i.e., UNIX,
Linux, and Windows.
What is the difference between overlays and swapping?
First-fit and best-fit better than worst-fit in terms of speed and storage utilization
Questions
1- Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB,
and 125 KB (in order), how would the first-fit, best-fit, and worst-fit
algorithms place processes of size 115 KB, 500 KB, 358 KB, 200 KB, and 375
KB (in order)?
2- Given six memory partitions of 100 MB, 170 MB, 40MB, 205 MB, 300
MB, and 185 MB (in order), how would the first-fit, best-fit, and worst-fit
algorithms place processes of size 200 MB, 15MB, 185 MB, 75MB, 175 MB,
and 80MB (in order)? Indicate which—if any—requests cannot be satisfied.
Fragmentation
External Fragmentation – total memory space exists to satisfy a request, but
it is not contiguous
Internal Fragmentation – allocated memory may be slightly larger than
requested memory; this size difference is memory internal to a partition, but
not being used
Reduce external fragmentation by Compaction
Paging
Physical address space of a process can be noncontiguous; process is allocated physical
memory whenever the latter is available
• Avoids external fragmentation
• Avoids problem of varying sized memory chunks
Divide physical memory into fixed-sized blocks called frames
• Size is power of 2, between 512 bytes and 16 Mbytes
Divide logical memory into blocks of same size called pages
Keep track of all free frames
To run a program of size N pages, need to find N free frames and load program
Set up a page table to translate logical to physical addresses
Still have Internal fragmentation
Address Translation Scheme
Address generated by CPU is divided into:
• Page number (p) – used as an index into a page table which contains base address of
each page in physical memory
• Page offset (d) – combined with base address to define the physical memory address that
is sent to the memory unit
Sharing.
• shared segments
• same segment number
Allocation.
• first fit/best fit
• external
fragmentation
Segmentation Architecture (Cont.)
Protection. With each entry in segment table associate:
• validation bit = 0 illegal segment
• read/write/execute privileges
Protection bits associated with segments; code sharing occurs at segment level.
Since segments vary in length, memory allocation is a dynamic storage-allocation
problem.
A segmentation example is shown in the following diagram
What are the similarities and differences between the paging and
segmentation?
Segmentation Paging No
Segmentation is a memory Paging is a memory 1 Similarities
management scheme management scheme
Deals with the non- Deals with the non- 2
contiguous allocation of contiguous allocation of
memory memory
In Segmentation a process is divided In Paging each process is divided 1 Differences
.into variable-sized segments .into fixed-size pages
15 page faults
• 1,2,3,4,5,3,4,1,6,7,8,7,8,9,7,8,9,5,4,5,4,2 .
Indicate the number of page faults for each algorithm assuming demand paging with three
frames.
Chapter 9
Storage Hierarchy
Storage systems
organized in hierarchy
• Speed
• Cost
• Volatility
Overview of Mass Storage Structure
Bulk of secondary storage for modern computers is hard disk drives (HDDs) and
nonvolatile memory (NVM) devices
HDDs spin platters of magnetically-coated material under moving read-write heads
• Drives rotate at 60 to 250 times per second
• Transfer rate is rate at which data flow between drive and computer
• Positioning time (random-access time) is time to move disk arm to desired cylinder
(seek time) and time for desired sector to rotate under the disk head (rotational
latency)
• Head crash results from disk head making contact with the disk surface -- That’s bad
Disks can be removable
HDD Scheduling
The operating system is responsible for using hardware efficiently — for the disk drives,
this means having a fast access time and disk bandwidth
Minimize seek time
Seek time seek distance
Disk bandwidth is the total number of bytes transferred, divided by the total time
between the first request for service and the completion of the last transfer
There are many sources of disk I/O request
• OS
• System processes
• Users processes
RAID Structure
RAID – redundant array of inexpensive disks
• multiple disk drives provides reliability via redundancy
Disk striping uses a group of disks as one storage unit
RAID is arranged into six different levels
• RAID schemes improve performance and improve the reliability of the storage system
by storing redundant data Mirroring or shadowing (RAID 1) keeps duplicate of each
disk
• Striped mirrors (RAID 1+0) or mirrored stripes (RAID 0+1) provides high
performance and high reliability
• Block interleaved parity (RAID 4, 5, 6) uses much less redundancy
RAID (0 + 1) and (1 + 0)
Other Features
Regardless of where RAID implemented, other useful features can be added
Snapshot is a view of file system before a set of changes take place (i.e. at a
point in time)
Replication is automatic duplication of writes between separate sites
• For redundancy and disaster recovery
Chapter 10
Overview
I/O management is a major component of operating system design and
operation
• Important aspect of computer operation
• I/O devices vary greatly
• Various methods to control them
• Performance management
• New types of devices frequent
Ports, busses, device controllers connect to various devices
Device drivers encapsulate device details
I/O Hardware
Incredible variety of I/O devices
• Storage
• Transmission
• Human-interface
Common concepts – signals from I/O devices interface with computer
• Port – connection point for device
• Bus - daisy chain or shared direct access
PCI bus common in PCs and servers, PCI Express (PCIe)
expansion bus connects relatively slow devices
Serial-attached SCSI (SAS) common disk interface
•Controller (host adapter) – electronics that operate port, bus, device
Sometimes integrated
Sometimes separate circuit board (host adapter)
Contains processor, microcode, private memory, bus controller, etc.
Fiber channel (FC) is complex controller, usually separate circuit board (host-bus
adapter, HBA) plugging into bus
I/O instructions control devices
Devices usually have registers where device driver places commands, addresses, and data
to write, or read data from registers after command execution
Devices have addresses, used by
• Direct I/O instructions
• Memory-mapped I/O
Device data and command registers mapped to processor address space
Especially for large address spaces (graphics)
Direct Memory Access
Used to avoid programmed I/O (one byte at a time) for large data movement
Requires DMA controller
Bypasses CPU to transfer data directly between I/O device and memory
OS writes DMA command block into memory
• Source and destination addresses
• Read or write mode
• Count of bytes
• Writes location of command block to DMA controller
• Bus mastering of DMA controller – grabs bus from CPU
Cycle stealing from CPU but still much more efficient
• When done, interrupts to signal completion
Version that is aware of virtual addresses can be even more efficient - DVMA
Chapter 11
File Concept
Contiguous logical address space
Types:
• Data
Numeric
Character
Binary
• Program
Contents defined by file’s creator
• Many types
text file,
source file,
executable file
File Attributes
Name – only information kept in human-readable form
Identifier – unique tag (number) identifies file within file system
Type – needed for systems that support different types
Location – pointer to file location on device
Size – current file size
Protection – controls who can do reading, writing, executing
Time, date, and user identification – data for protection, security, and
usage monitoring
Information about files are kept in the directory structure, which is
maintained on the disk
File Operations
Create
Write – at write pointer location
Read – at read pointer location
Reposition within file - seek
Delete
Truncate
Open (Fi) – search the directory structure on disk for entry Fi, and move the
content of entry to memory
Close (Fi) – move the content of entry Fi in memory to directory structure
on disk
Access Methods
A file is fixed length logical records
Sequential Access
Direct Access
Other Access Methods
Operations Performed on Directory
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Two-Level Directory
What are the differences between files and directory?
File Folder .NO
The file is a collection of information and data The folder is a collection of files 1
File has extension eg. (.txt, .xls, .doc, .pdf, .pptx) The folder does not have any extension 2
A file can't contain another file or folder A Folder can contain multiple files and folders 3
The file cannot hold another file or folder The folder can hold the file or another folder
The file consumes a certain amount of memory The folder does not have any specific size. It takes 4
.size up the file size or folder it contains. It does not take
up space on computer memory
Files are not permitted to be shared on the .Folders can be shared over the network 5
network on their own
Protection
File owner/creator should be able to control:
• What can be done
• By whom
Types of access
• Read
• Write
• Execute
• Append
• Delete
• List
Allocation Method
An allocation method refers to how disk blocks are allocated for files:
• Contiguous
• Linked
• File Allocation Table (FAT)
Recovery
Consistency checking – compares data in directory structure with data
blocks on disk, and tries to fix inconsistencies
• Can be slow and sometimes fails
Use system programs to back up data from disk to another storage device
(magnetic tape, other magnetic disk, optical)
Recover lost file or disk by restoring data from backup