# data[].attributes.body
→○►✹☼
☼ Virtual memory – separation of user logical memory from physical  memory
✹ Can be implemented via ;
→ Demand paging - Bring a page into memory only when it is needed
→ Lazy swapper – never swaps a page into memory unless page will be needed
→ Demand segmentation
☼ Valid-Invalid Bit - With each page table entry a valid–invalid bit is associated (v Þ in-memory, i Þ not-in-memory)
☼ Page Fault - If there is a reference to a page, first reference to that page will trap to operating system:
☼ Pure Demand Paging - start process with no pages in memory
☼ Stages in Demand Paging
1. Trap to the operating system
2. Save the user registers and process state
3. Determine that the interrupt was a page fault
4. Check that the page reference was legal and determine the location of the page on the disk
5. Issue a read I/O from the disk to a free frame
6. Receive an interrupt from the disk I/O subsystem (I/O completed).
7. State Save the registers and process state for the other user
8. Determine that the interrupt was from the disk
9. Correct the page table and other tables to show page is now in memory
10. Wait for the CPU to be allocated to this process again
11. Restore the user registers, process state, and new page table, and then resume the interrupted instruction
☼ Page Replacement - find some page in memory, but not really in use, page it out
Occurs when;
→ A page fault occurs and we need to bring the desired page into memory
→ There are NO free frames.
☼ Frame-allocation algorithm
☼ Page-replacement algorithm
→ First In First Out (FIFO)

→ Optimal

→ Least Recently Used (LRU)
☼ Thrashing - a process is busy swapping pages in and out

# data[].attributes.body
→○►✹☼
☼ A  program must be brought (from disk)  into memory and placed within a process for it to be run
☼ Main memory and registers are the only storage entities  that a CPU can access directly
☼ Memory unit only sees a stream of address
→ It does not know how these addresses were generated
☼ Cache Memory  supplementary memory system that temporarily stores frequently used instructions and data for quicker processing
→ It is the fastest memory in computer system
☼ Memory Protection done by using the base register n limit register
→ Base register holding the smallest legal physical address of a program in memory
→ Limit register specifies the size of the program
☼ Address Binding helps allocate a physical memory location to a logical pointer
✹ Can happen at 3 diff point of time
→ Compile time
→ Load time
→ Execution time
☼ 3 Types of addresses ;
→ Symbolic address
→ Logical address generated by the CPU
→ Physical Address the actual address of the memory location
☼ Memory Allocation Scheme
✹ Two main ways;
→ Contiguous
→ Non-Contiguous
☼ Multiple-partition allocation
→ Variable-partition the memory space has variable size to  accommodate process’
needs
→ Hole block of available memory; holes of various size are scattered throughout
memory
☼ Dynamic Storage-Allocation Problem
To satisfy a request of size n from a list of free holes
→ First-fit Allocate the first hole that is big enough

→ Best-fit Allocate the smallest hole that is big enough
→ Worst-fit Allocate the largest hole
☼ Fragmentation is a phenomenon in which storage space, main storage or secondary storage, is used inefficiently
→ External
→ Internal
○ IT CAN BE REDUCED BY compaction
☼ Methods of Partitions
→ Segmentation.

→ Paging

→ Paged segmentation.
☼ Swapping is taking a process out from the memory( swap out), and putting it back into the memory (swap in) to continue it’s execution.
☼ Backing store fast disk large enough to accommodate copies of all memory images for all processes; must provide direct access to these memory images

# data[].attributes.body
✹ Deadlock is a state when every process in a set is waiting for an event that can be caused
only by another process in the set.
→ can be described using a directed graph known as Resource Allocation Graph
✹ Deadlock can arise if four conditions hold simultaneously.
→ Mutual exclusion
→ Hold and wait
→ No preemption
→ Circular wait
✹ Safe State When a process requests an available resource, system must decide if immediate
allocation leaves the system in a safe state

# data[].attributes.body
☼ Race Condition happens when several processes trying to access and manipulate the variable "counter" concurrently; the outcome of the execution will depends on the order the access occur. example:- [counter++] [counter--]
☼ Critical Section Problem consider system of n processes {P0,P1,...Pn-1}
- it is to design protocol that allows processes to use the section to cooperate to
solve this problem
- entry section. exit section, then remainder section
- Solution must satisfy :
1. Mutual Exclusion
2. Progress
3. Bounded Waiting
☼ Peterson's Solution algorithm that only applicable to only two processes at a time
- int turn;
- boolean flag[2]
- Need to prove 3 requirements
1. Mutual Exclusion
2. Progress
3. Bounded Waiting
☼ Mutex Locks a synchronization primitive: a mechanism that enforces limits on access to a resource when there are many threads of execution.
- [ acquire() and release() ]
- This solution requires busy waiting  -> called spinlock
☼ Semaphore a Synchronization tool that provides more sophisticated ways (than Mutex locks)  for process to synchronize their activities
- Accessed via :-
1. wait()
2. signal()
- Counting Semaphore integer value can range over an unrestricted domain
- Binary Semaphore integer value can range only between 1 and 0
- Two Operations :-
1. block place the process invoking the operation on the appropriate waiting queue
2. wakeup remove one of processes in the waiting queue and place it in ready queue
☼ Liveness (Deadlock) two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes
- Other types of deadlock :-
1. Starvation
2. Priority Inversion

****************************REFLECTION OF THIS CHAPTER******************************
✐ synchronization is the task of coordinating the execution of processes where no two processes can have access to the same shared data n resources
✐ Synchronization hardware is not a simple method to implement for everyone, so the strict software method known as Mutex Locks was also introduced.

# data[].attributes.body
↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓

☼ CPU Scheduling - a process of determining which process will own CPU for execution while another process is on hold
→ selects from among the processes in ready queue, and allocates the CPU core to one of them
→ Take places when;
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates
** Process 1&4 is nonpreemptive
** Process 2&3 is preemptive
☼ Dispatcher module gives control of the CPU to the process selected by the short-term scheduler
☼ Dispatch latency - time it takes for the dispatcher to stop one process and start another running
☼ CPU utilization – keep the CPU as busy as possible

☼ Throughput – # of processes that complete their execution per time unit

☼ Turnaround time – amount of time to execute a particular process

☼ Waiting time – amount of time a process has been waiting in the ready queue

☼ Response time – amount of time it takes from when a request was submitted until the first response is produced, not output
(for time-sharing environment)

# data[].attributes.body
↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓-↓

☼ Threads - a sequence of code that is executed within the scope of the process
→ run within application
→ light-weight processes
because they have their own stack but can access shared data
→ can simplify code, increase efficiency
BENEFITS
○ Responsiveness
○ Resource Sharing
○ Economy
○ Scalability
☼ Kernels generally multithreaded
☼ Parallelism implies a system can perform more than one task simultaneously
○ Data Parallelism - distributes subsets of the same data across multiple cores, same operation on each
○ Task Parallelism - distributing threads across cores, each thread performing unique operation
☼ Concurrency supports more than one task making progress

Multiprocessor                          VS                            Multicore
when a system have more than two CPUs added to                       refers to a single CPU with multiple execution units
the system

☼ Multithreading Models
○ Many-to-one                                              ○ One-to-one                               ○ Many-to-many
- threads mapped to single kernel thread     -thread maps to kernel thread    -threads to be mapped to many kernel threads
- One thread blocking causes all to block
- Examples; ♦ Solaris Green Threads        - Examples; ♦ Windows             - Examples; ♦ Windows with threadFiber
♦ GNU Portable Threads                        ♦ Linux
○ Two-level-Model
- Similar to M:M, just that it allows a user thread to be bound to kernel thread

# data[].attributes.body
♣ Process (active) - a program  in execution
- has a single thread of execution
♣ Program Code - aka text section
♣ Program Counter
♣ Stack - contain temporary data
♣ Data Section - containing  global variables
♣ Heap - containing memory dynamically allocated during run time
♣ Process Control Block (PCB)
Information associated with each process aka task
control block
♣ Process Scheduling - Maximize CPU use, quickly switch
processes onto CPU core
♣ Process scheduler - selects among available processes
for next execution on CPU core
♣ Scheduling queues
☼ Ready Queue - set of all processes waiting to execute
☼ Wait Queue  - set of processes waiting for an event

♣ Context switching - tendency to shift from one unrelated task
to another

♣ Operation on Processes
↓                                                   ↓
☼Process Creation                                ☼Process Termination
♀ Parent process create                             ♀ exit()
children processes                                ♀ wait()
♀ managed via a process identifier(pid)         ♀ abort()
♀ pid = wait(&status)

♣ Interprocess Communication (IPC) [send,receive]
OS provides to allow the processes to manage shared data
☼ Shared Memory
☼ Message Passing
♣ Cooperating Processes
☼ Independent cannot affect or be affected by other processes
running on the system
☼ Cooperating can affect or be affected by other processes
running on the system
♣ Producer-Consumer Problem
multi-process synchronization problem between more than one
processes
☼unbounded-buffer places no practical limit on the size of the
buffer
☼bounded-buffer assumes that there is a fixed buffer size
♣ Message System
processes communicate with each other without resorting to shared
variables
♣ Communication link
☼ Physical
→ Shared memory

→ Hardware bus

→ Network

☼ Logical
→ Direct or indirect

→ Synchronous or asynchronous

→ Automatic or explicit buffering

♣ Synchronization
the coordination of events to operate a system in unison
↓                                        ↓
☼Blocking(synchronous)        ☼Non-Blocking(asynchronous)
# Blocking Send                    #Non-blocking send
# Blocking Receive                 #Non-blocking receive
♣ Buffering
the process of preloading data into a reserved area of memory
that's called a buffer
1. Zero Capacity
2. Bounded Capacity
3. Unbounded Capacity

*******************REFLECTION OF THIS CHAPTER*******************
✐ Processes is basically something that is working on in os.
✐ Or another explanation is that OS doing some work

# data[].attributes.body
-----------------------------25 October 2021-----------------------------

♣ Operating System Services
??? - Provide an environment for execution of programs and services to
programs and users

♣ OS Services to User
✹ User Interface
→ Command-Line Interface (CLI)
- Allows direct command entry
→ Graphical-User  Interface (GUI)
- User-friendly desktop metaphor interface
→ Touch Screen
→ Batch
✹ Program Execution - The system must be able to load a program into
memory and to run that program, end execution, either normally or
abnormally (indicating error)
✹ I/O Operations
✹ File-system Manipulation - Programs need to read and write files
and directories, create and delete them, search them, list file information,
permission management
✹ Communication - Processes may exchange information, on the same
computer or between computers over a network
✹ Error Detection - OS needs to be constantly aware of possible errors

♣ OS Services for efficient operation - via resource sharing
✹ Resource Allocation - When  multiple users or multiple jobs running
concurrently, resources must be allocated to each of them
✹ Logging - To keep track of which users use how much and what kinds
of computer resources
✹ Protection & Security - The owners of information may want to control
use of that information, concurrent processes should not interfere with
each other
☼ Protection - involves ensuring that all access to system resources is
controlled
☼ Security - of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid
access attempts

♣ System Call - Programming interface to the services (C or C++)
- Mostly accessed by programs via a high-level Application
Programming Interface (API)
- System-call Interface maintains a table indexed
according to these numbers
♣ Types of System Calls
✹ Process Control
- create process, terminate process, •get process attributes, etc
✹ File management
- create file, delete file, read, write, reposition, etc
✹ Device management
- request device, release device, logically attach or detach devices, etc
✹ Information maintenance
- get time or date, set time, get and set process, file, etc
✹ Communications
- create, delete communication connection, Shared-memory model
create, etc
✹ Protection
- Control access to resources, Allow and deny user access, etc

♣ System Services - provide a convenient environment for program
development and execution
✹ File manipulation
- Create, delete, copy, rename, print, dump, etc
✹ Status information sometimes stored in a file
- info - date, time, amount of available memory, registry, etc
✹ Programming language support
- Compilers, assemblers, debuggers and interpreters
✹ Program loading and execution
- Absolute loaders, relocatable loaders, linkage editors, etc
✹ Communications
- Provide the mechanism for creating virtual connections among
processes, users, and computer systems
✹ Background services
- Launch at boot time, aka services, subsystems, daemons
✹ Application programs
- Don’t pertain to system, not typically considered part of OS

**********************REFLECTION OF THIS CHAPTER***********************
✐ OS provide a numbers of services that come from the lowest level to
highest
✐ System program are provided to help and satisfy various common user request

# data[].attributes.body
--------------------------20 October 2021----------------------

Storage Structure
↓                               ↓                               ↓
Main memory         Secondary Storage        Tertiary Storage
• Random access      Extension of main memory
• Typically volatile     that provides large
nonvolatile storage capacity
• Hard disk
• Solid-state disks

Computer Storage -→ KB - 1024bytes
-→ MB - 1024²bytes
-→ GB - 1024³bytes
-→ TB - 1024⁴bytes
-→ PB - 1024⁵bytes

Storage system organized in hierarchy

• Speed

• Cost

• Volatility

----------------------------Terms-----------------------------
☼Caching - copying info from "slow" storage into faster
storage system
☼Device Driver - provides uniform interface between
controller and kernel
☼Direct memory access (DMA) - is a feature of computer
systems that allows certain hardware subsystems to
access main system memory (random-access memory)
independently of the central processing unit (CPU)
☼Single general-purpose processor - it's designed to be
fairly good at nearly any task you could want to do with a
processor
☼Multiprocessors - a computer system with two or more
central processing units (CPUs) share full access to a
common RAM. The main objective of using a
multiprocessor is to boost the system's execution speed
→ also known as parallel systems and tightly-coupled
systems
► Advantages ;                 ►Two Types ;
•Increased throughput    •Symmetric Multiprocessing
•Economy of scale         •Asymmetric Multiprocessing
•Increased reliability
☼Multicore - multiple computing cores on a single chip
► Advantages ;                            ►Types ;
•Increased Power Efficiency           •Single core
•Increased Performance                •Dual core etc
☼Clustered Systems - multiple system working together
- Usually sharing storage via a storage-area network
(SAN)
- Provides a high-availability service which survives
failures

► Types ;
•Asymmetric clustering
•Symmetric clustering
☼Multiprogramming - the technique of utilizing several
programs concurrently in a single computer system via
multiprocessing
☼Timesharing Systems aka multitasking - the sharing of a
computing resource among many users at the same time
by means of multiprogramming and multi-tasking
→ Response time should be < 1 second
☼Virtual memory - allows execution of processes not
completely in memory
☼Modes of Operation - A mechanism that allows the OS to
protect itself and other system components
► Types ;
•User mode
•Kernel mode
•Mode bit (0 / 1)
☼Timer - To prevent process to be in infinite loop (process
hogging resources
☼Process Management (Process) - a program in execution
► Program                        ► Process
Passive Entity                       Active Entity
☼Thread - a basic unit of  CPU utilization within a process
☼Single-threaded process - Instructions are executed
sequentially, one at a time, until completion
☼Multi-threaded - one program counter per thread
☼Caching - Information in use copied from slower to faster
storage temporarily
☼Cache - a thing that is hidden or stored somewhere
→Checked first to determine if information is there
● If it is, information used directly from the cache (fast)
● If not, data copied to cache and used there
☼Protection - A mechanism for controlling access of
processes (or users)  to resources defined by the OS
☼Security - A defense of the system against internal and
external attacks
☼Privilege escalation - allows user to change to effective
ID with more rights

****************REFLECTION OF THIS CHAPTER******************
✐ OS basically a program that let us interact with computer
✐ There is only one language that computer can understand which is (1 and 0)

# data[].attributes.body
-------------------13 October 2021------------------
Computer Systems
it can be divided into 4 which are ;
→Users
→Applications
→OS
→Hardaware
- Computer system need to have both hardware n software
which includes :- cpu,memory,i/o and storage

Operating System
•It controls the hardware & coordinates its use among various application programs for various users
- this mean OS cant work on its own, where it needs user n programs etc.

•There are 2 viewpoints ;
→The user
-Single
-Multi
-Handled comp..
-Embedded comp.
→The system
-Resources Allocator
-Control Program

Kernel → the one program running at all times on the computer
Along with  the kernel, there are two other types of programs which are ;
• System Program
• Application Program

How computer started??
→ Using bootstrap progam which loaded at power-up / reboot
• typically stored in ROM/EPROM, known as firmware
• initialize all aspects of system
• load kernel n starts execution

Interrupts - the occurrence of an event
► Hardware - a device may trigger an interrupt by
sending a signal to the CPU, usually by way of system
bus
► Software - a program may trigger an interrupt by
executing a special operation called a system call
• A software-generated interrupt  (sometimes called trap or
exception) is  caused either by an error (e.g., divide by
zero) or a user request
• An operating system is interrupt driven.