Show Menu
Cheatography

CS205 Cheat Sheet (Chapter 1-3) Cheat Sheet (DRAFT) by

dfgbhgwrthrgbgrgnhnff

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Chapter 1: Interrupts

What is an OS? Program that controls the execution of applic­ation programs. Interface between applic­ations & hardware.
Function of an operating system: Resource management & alloca­tion, Controls execution of user programs, Providing services to system users
Components of an OS: CPU, RAM, I/O modules, System Bus
What is an instru­ction? Command to perform a specific task.
Components involved: Program counter, instru­ction register, accumu­lator, memory address register, memory buffer register
Instru­ction (fetch­/ex­ecute) cycle: PC points to instru­ction in memory -> CPU fetch instru­ction that is being pointed -> Instru­ction is loaded into IR -> PC increm­ented to next instru­ction -> CPU interprets & execute the instru­ction.
# possible instru­ctions = # Unique instru­ctions with opcode bits = 2^(opcode bits)
Maximum directly addres­sabsle memory capacity = # Unique memory addresses = 2^(Address bits)
Size of data bus to use = number of bits in instru­ction format
What is an interrupt: Mechanism where the normal sequencing of instru­ctions of CPU is interr­upted to address a different task.
Polling: Wait for I/O Comple­tion. CPU constantly ask I/O if it is done.
Types of interr­upts: Program interrupt (Execution of illegal instru­ction, illegal access of memory space), Timer interrupt (Perform specific tasks on a regular basis), I/O interrupts (Signal completion of an I/O operat­ion), Hardware failure (low battery, power failure, memory error)
Fetch execute instru­ction cycle with interrupt: CPU -> Fetch next instru­ction -> Execute instru­ction -> (No interrupt, back to CPU) -> Check for interrupt -> Initiate interrupt handler -> CPU
Fetch & execute stage is atomic and cannot be interr­upted, Interrupt is served after the end of an execution stage
Multiple interr­upts: Two approa­ches, Disable interrupts while interrupt is being processed, use a priority scheme
Memory hierachy: (Small­er/­Faster) Register -> Cache -> RAM -> Secondary storage -> Tertiary storage (Large­r/S­lower)
Registers, cache are part of bios
L1 cache: Data cache & instru­ction cache, separation is to prevent overcr­owding of either caches
L2 cache: Larger cache that stores both data & instru­ctions
L3 cache: Shared by all cores, store data & instru­ctions to be shared among all cores
I/O techni­ques: Programmed I/O (CPU polling and then initiates data transfer between memory & I/O device when device is ready), Interrupt driven I/O (When I/O device is ready to transfer data, device sends an interrupt to CPU), Direct Memory Access (DMA) (Allows I/O devices to directly read & write to memory without continuous CPU involv­ement, improving data transfer effici­ency)
Multip­roc­essor systems: Two or more processes working together in a single machine, all processors share computer memory, I/O devices, work in parallel to enhance perfor­mance & reliab­ility.
Types of Multip­roc­essor systems: Symmetric multip­roc­essing (No one is in charge, processes are of similar capabi­lity), Asymmetric multip­roc­essing (One processor is the master, contro­lling the system & distri­buting tasks to other proces­sors, the slaves.
Multicore systems: Chip multip­roc­essor, each core consists of all components of a CPU, OS allows for parall­elism in multip­roc­essing enviro­nment, shares memory & I/O devices

Chapter 2: Multip­rog­ram­ming, time sharing

What is a kernel: One program running at all times on the computer. Respon­sib­ili­ties: Device manage­ment, Schedu­ling, System calls & APIs, Protection & Fault tolerance, security
Kernel types: MicroK­ernel (Only the most essential services, high security but low perfor­mance), Monoli­thi­cKernel (Has everyt­hing, very efficient but not secure), Hybrid­Kernel (Mix of both approa­ches, essential services in kernel space, most other services + drivers in user space)
Modes of operation: User mode (Appli­cations you run are limited in what they can do), Kernel mode (Full access to hardware & can execute any CPU instru­ction)
Unipro­gra­mming: One program runs until completion before the next program starts, no 2 programs run at same time)
Multip­rog­ram­ming: Multiple programs run concur­rently to optimize CPU util, memory should be large for > 2 programs & allow context switch among all of them.
CPU util (%): sum(du­ration * CPU time : process) / total duration (uni), max duration (multi)
Memory util - multi (%): sum[(# Jobs left at t) * duration / memory capacity at t = 5m, 10m, 15m]/max duration
Elapsed time: sum of all duration for uni, max duration for muti
System throug­hput: # Jobs completed by a certain time.
Mean(avg) turnaround time: sum(t for each process to comple­te)­/number of processes
Time sharing system: multiple intera­ctive jobs, shared processor time, simult­aneous access. (min user response time w time sharing, max cpu util w/o time sharing)
Time slicing techni­ques: system clock generates time interrupts at a rate of t, at each interrupt, OS takes back control from current user program, saves state and assign processor to another user program (ISR), state of current user program is saved to disk and state of next user program is loaded to MM for execution.
Android OS is a Linux based OS system,
Android Applic­ation framew­ork­:Ac­tivity Manager: An activity represents a single screen with a user Interface. Respon­sible for starting, stopping, and resuming activi­ties. Window Manager: Surface manager that manages frame buffering and low-level drawing. Manage top-level window’s look and behavior. Package Manager: Installs and removes applic­ations. Telephony Manager: Allows intera­ction with phone, SMS, and MMS services.
Content Providers: Manage data that need to be shared between applic­ations such as contacts, calendar info, which are stored in SQL database. Resource Manager: Manages non-code resources, such as strings, graphics, layout files. View System: Provides the user interface (UI) that displays inform­ation and responds to user actions, Lists, grids, text boxes, buttons, etc. Location Manager: Allows developers to tap into locati­on-­based services, whether by GPS, cell tower IDs, or local Wi-Fi databases. Notifi­cation Manager: Manages events, such as arriving messages and appoin­tments. XMPP: Provides standa­rdized messaging functions between applic­ations
Android Activity: UI screen, Android Run time (ART): VM for android, bytecode to machine code.
Android system libraries: Surface Manager (display manage­ment) OpenGL (graphics engine) Media Framework (video­/audio streaming) SQLite (relat­ional database engine) Browser Engine Bionic LibC (system C library)
Differ­ences between android OS & Linux OS: Power management (Power collapse, component level power manage­ment, Wakelo­cks), IPC (Inter process commun­ica­tion)

Chapter 3: Process descri­ption and control

What is a program: Set of instru­ctions that the computer can execute. Can have multiple instances.
What is a process: Task that you do on your computer, an instance of a program. Compon­ents: Executable program, associated data, execution context.
Process image: current activity state reflected by CPU registers (PC, etc), Progam code, Data Sections (Global constants & variab­les), Stack, Heap
Process elements: Identi­fier, State, Priority, Program Counter, Memory pointers, Context data, I/O States info, Accounting info
Process control block (PCB): Data structure created & managed by OS, full of info about each process. New process created -> OS updates PCB with all process details, key tool that allows support for multiple processes.
Dispat­cher: Small OS that follows a scheduling policy, handles context switching for CPU, spends a lot of time saving instru­ctions, load new instru­ctions into CPU from PCB. Trace: Detailed log of what a process does
Process Creati­on:App launch, OS start a process to do task, some process start in background w/o you directly intera­cting with them.Some processes are started by other processes. Parent process may wait for child to finish or continue concur­rently. e.g Process A spawns other process & so forth forming a tree.
Linux system calls: Fork(): Create copy of current process, exec()­:Ex­ecute a program, wait()­:Wait for child process to finish and change state, kill(): Send a signal to terminate a process, pipe(): IPC
Two state (Runni­ng/Not Running) process model: Process created and move to queue -> Process stay till CPU is ready -> Dispatcher move a process from not running to running state -> Process is tempor­arily stopped, move back to not running state due to an interrupt -> If not, Process finish execution & leave the system.
Five state process model: New, ready, running, blocked, exit
five State transi­tions: New process is admitted to ready queue -> dispatcher assign process to be run by CPU -> If time out goes back to ready state -> If event wait (I/O comple­tion), process admitted to block queue, event occurs, remove from block queue & move to ready queue to await dispatcher -> If process completes task, exits
To handle different types of events, there can be multiple block queues.
How does OS decide which process run when & how long: Scheduling policy (Dispa­tcher choose from ready queue for CPU to run), Dispat­cher, Clock (timeout of process)
Solutions for limited available memory: Virtual memory (Move part of a process from RAM to disk), Swapping (move some blocked processes entirely out to disk)
Suspended queue: Process that are moved to disk is placed in a suspend queue, OS can decide to bring suspended processes back to main memory.
Transition states: Same as five state processes but for processes in the block/­ready queue, can be suspended and moved to disk (block­/su­spend & ready/­sus­pend) if there are any memory constr­aints in RAM. Suspended processes can be moved back to the ready queue when there is enough memory to hold them or when an event they are waiting for occurs.
Inform­ation required by OS to control processes and manage resources: Memory tables, I/O tables, File tables, Process tables
Memory tables: RAM, Secondary memory (HDD/SDD), Virtual Memory. I/O Tables: Used by OS to manage I/O devices. File tables: Provide info about the existence of files location on secondary memory, current status and other attrib­utes.
Process tables: Process location (Where a process and its data is located in memory), Process Attributes (# Attributes used by OS for control)
Process list struct­ures: OS has a list of PCBs in each queue (running, ready, block) it use to keep track of all processes.
Transi­tions: When a new process is created -> unique identifier assigned -> Memory space allocated for process image -> PCB is initia­lised -> set up linkage between parent and child processes -> Update all other data structures
Proces­s/C­ontext switching: Necessary for multit­asking. Occurs from a clock interrupt, I/O interrupt, Traps (Errors generated with running process), Supervisor call (User process calls for I/O operation & is blocked)
Mode switching: User Mode (Where user applic­ations run, Less privil­eged), Kernel Mode (Where the OS runs, Highly privil­eged)
Costs involved for mode switching: Save state of current process, switch cpu to kernel mode to execute system call, restore state of process once system call is completed and switch back to user mode.
Mode switch with process switch: Save context of processor -> Update PCB -> Move the PCB to the approp­riate queue -> Select another process for execution -> Update the PCB of the process selected -> Update memory management data structures for address transl­ation -> Restore the context of the processor to that which existed at the time the selected process was last switched out
Mode switch w/o process switch: Interrupt is pending -> Save the context (PC, processor registers, stack pointer) into the PCB of the current process -> Sets the program counter to the starting address of an interrupt handler program -> Switches from user mode to kernel mode
Tradit­ional OS: All user processes rely on a single monolithic kernel
Process switching functions: OS function executes within user processes. Mode switch w/o process switch in a user program (fopen()), Process switching function takes place when a process switches its state.
process based OS: Processes are assigned different priorities to be scheduled for running, good for multi processor env