Operating System

  1. Reader and Writer Problem Solution using semaphores
    2 semaphores, one for the acquiring and releasing the writer , another for only the readers and a variable that keeps tracks of the readers
    Image Upload 2

    Image Upload 4
  2. Dining Philosopher Problem Using Monitor
    Image Upload 6

    Image Upload 8
  3. Dining philosopher Problem using semaphores
    Image Upload 10
  4. Bounded Buffer Consumer and Producer Code, Using semaphores
    • Image Upload 12
    • Image Upload 14
  5. (1) occurs when two or more processes are stuck in a state where they are waiting for each other to release a resource, and none of them can move forward or complete their tasks.
    dead lock
  6. Semaphores implementation with no busy waiting
    • typedef struct{
    •   int value;
    •   struct process *list;

    }semaphore;

    Image Upload 16
  7. Implementation of Semaphores
    Image Upload 18
  8. mutex lock aquire() and release() code
    • Image Upload 20
    • while(true){

    •    acquire();
    •    //critical section
    •    release();

    }
  9. atomic variable increment() function
    using compare_and_swap()
    Image Upload 22
  10. Bounded Waiting mutual exclusion using compare_and_swap
    Image Upload 24
  11. compare_and_swap code
    Image Upload 26

    Image Upload 28
  12. Hardware Instruction,test_and_set() code definition
    uses a do while loop
    • Image Upload 30
    • Image Upload 32
  13. These are variables that support atomic operations, meaning that read, write, or update actions occur without interruption from other threads or processes. They help achieve synchronization by ensuring safe concurrent access to shared data.
    Atomic Variable
  14. Some CPUs provide special instructions, like Test-and-Set, Compare-and-Swap, or Fetch-and-Add, that allow atomic (uninterruptible) read-modify-write operations. These instructions can be used to implement locks or synchronization primitives.
    Hardware instructions:
  15. (1): These are special instructions that enforce a specific order of memory operations, preventing reordering and ensuring data consistency between different CPU cores or threads. They help synchronize shared data access.
    Memory Barrier

    Image Upload 34
  16. 3 Hardware Solutions to Synchronization
    • 1. Memory barrier
    • 2. Hardware Instruction
    • 3. Atomic Variable
  17. Peterson's Critical section problem code(Works well for 2 processes but can't scale)
    Image Upload 36
  18. What are the 3 conditions needed to solve critical section
    • Mutual Exclusion - Only one process can use the critical section at a time.
    • Progress - Processes wanting to enter the critical section will eventually get a turn.
    • Bounded Waiting - After requesting access, a process must wait a limited time to enter the critical section.
  19. Producer and Consumer Race condition problem code
    If we want to cause a racing condition we can only have a counter==BUFFER_SIZE for the producer and counter==0 for the consumer. This might produce a race condition
  20. The entire program does NOT need to be in memory to execute
    True
  21. A hardware device that: at run time maps virtual to physical
    address
    • Memory Management Unit
    • Image Upload 38
  22. (1) the set of all logical addresses generated by a program, and (2) the set of all physical addresses generated by a program
    • Logical address space
    • Physical address space
  23. Multi-Step processing of a user program
    Image Upload 40
  24. Memory Protection
    we need to make sure that the process can only access the addresses that it has been addressed to.
  25. Earliest deadline  First served, what do I have to look for
    Write down all the deadlines and when we reach a deadline we have to ask ourselves, which deadline is the earliest from what I from the 2 processes. If the current process has a later deadline at when we reach a deadline point: this later gets preempted
  26. Rate Monotonic Formulas
    if (1)CPU utilization  < (2)Worst case CPU utilization for N process

    Then we know that the Monotic Scheduling might be able to satisfy  all the process

    • (1) : ∑ i = Ci/Pi
    • (2) :  N(2^(1/N)-1)
  27. Soft-Real Time Vs Hard-Real Time
    • Soft-Real Time: Tasks have the highest priority but do not guarantee to when they will be scheduled.
    • Hard-Real Time: The process must be serviced by its deadline
  28. (1) - when a thread accesses memory, it may need to wait for the data to become available from memory.
    (1) -- Memory stall
  29. (1)– each processor is self-scheduling, all processes in common ready queue, or each has its
    own private queue of ready processes
    Symmetric Multiprocessing
  30. (1)– only one processor accesses the system data structures, alleviating the need for data sharing
    Asymmetric multiprocessing
  31. Multi-level Queue
    • The ready queue is partitioned into separate queues, 
    • Foreground
    • Background
  32. Once the CPU has been allocated to a process, the process keeps the CPU until it voluntarily releases the CPU. Is this a case of preemptive or non-preemptive scheduling?
    Non-Preemptive
  33. What are 4 examples of CPU scheduling when we know for sure that it will be a nonpreemptive scheduling, meaning: the CPU is going to wait for the process to finish before moving on
    • (1)When a process moves from running to ready
    • (2)When a process moves from waiting to ready
    • (3)When a process terminates
    • (4)When a process moves from running to waiting
  34. Threads Code Anything you remember from the syntaxes
    • <#include pthread.h>
    • int sum = 0;
    • pthread_mutex lock;

    • int main(int argc , char *argv[]){
    • pthread_attr_t attr;
    • pthread_t thread[2];

    • pthread_create(&thread[0], &att,runner, argv[1]);
    • pthread_create(&thread[1], &att,runner, argv[1]);


    • pthread_join(thread[0],NULL);
    • pthread_join(thread[1],NULL);

    printf(sum);

    }

    void *runner(*param){

    •   int num = atoi(&param);
    •   pthread_mutex_lock(&lock);
    •   for(int i = 0; i<=num; i++){

           sum+= i; 

    •   }
    •  pthread_mutex_unlock(&lock);

      pthread_exit();


    }
  35. Multi-threaded Server Architecture
    Image Upload 42
  36. What do threads Share (1) and what do they have of their Own (2)
    • (1) data, code, OS resources eg. files
    • (2) stack, register
  37. What is a Socket in Client server Communication
    Defined endpoint communication: Concatenation of IP address or Host + Port Number

    Example:  161.25.19.8:1625 where 1625 is the port # and 161.25.19.8 is the IP address.

    port below 1024 are well known
  38. Buffering: Messages attached to links can be implemented in different ways
    • *Rendez-Vous:0 capacity, sender must wait for the receiver
    • *Bounded Capacity: finite length of n messages, If link is full, the send must wait
    • *Unbounded Capacity: The sender never wait
  39. Interprocess Message Passing
    • send(message)
    • receive(message)

    Direct Message

    • send(P, message) // Send message to process P
    • receive(Q, message) // Receive a message from process Q

    Undirect Message: Uses Mailbox as an Intermediary, mailboxes have unique Ids they act as a Socket

    • send(A, message) // Send message to mailbox A
    • receive(A, message) // Receive message from mailbox A
  40. Bounded Buffer Shared Memory Solution The Consumer Code
    #define BUFFER_SIZE = 10

    • typedef struct {
    • ...
    • }item;

    • item buffer[BUFFER_SIZE];
    • int in=0;
    • int out=0;

    item next_consumed;

    while(true){

        while(in == out );

    •     next_consumed = buffer[out];
    •     out = (out+1)%BUFFER_SIZE;

    }
  41. Bounded Buffer Shared Memory Solution The producer Code
    #define BUFFER_SIZE = 10

    • typedef struct {
    • ...
    • }item;

    • item buffer[BUFFER_SIZE];
    • int in=0;
    • int out=0;

    item next_produced;

    while(true){

        while((in+1)%BUFFER_SIZE == out );

    •     buffer[in] = next_produced;
    •     in = (in+1)%BUFFER_SIZE;

    }
  42. The cooperating process needs IPC (Interprocess Communication). What are 2 models IPC?
    • Shared Memory: Requires Synchro, moves larger data
    • Message Passing: useful for exchanging smaller amount of data
  43. How many ways can parent and child process run?
    • Either they run concurrently 
    • Or the parent has to wait for the child to finish running
  44. Parent and children process have 3 sharing resources option
    • Share all the resources
    • Parent share a subset of their resources to the child
    • Or they do not share any resources
  45. Medium-term scheduler
    can be added if the degree of multiple programming needs to decrease

    Image Upload 44
  46. selects which processes should be brought into the ready queue
    Long Term Scheduler
  47. Which scheduling queue is the set of process waiting for an I/O device
    Device queue
  48. which scheduling queue which are the set of all processes residing in main memory, ready and waiting to execute
    Ready queue
  49. Which scheduling queue which are the set of all processes in the system
    Job Queue
  50. Context Switch Diagram
    Image Upload 46
  51. What is some information related to the process
    • Process State,
    • program counter,
    • CPU registers
    • CPU scheduling info: Priorities 
    • What is the memory allocated for this process
    • I/O information
  52. Holds information relative to each process
    PCB: Process Control Block
  53. What are the process states
    • New: Process just being created
    • Ready: The process is ready to be sent to the processor
    • Waiting: Process waiting for some other event to occur
    • Running: Some instructions are being run on the processor
    • Terminated: The process has finished its execution
  54. When does a program become a process
    When it is executable files are loaded into the memory
  55. A program in execution; The execution must progress
    in sequential fashion
    Process
  56. Linux System System
    fi - ne - block - C PU - Sch - meMa - chaDe
    Image Upload 48
  57. Microkernel System structure:
    After many years of research, we have realized what was most important for the Kernel, the rest can be  executed in user mode

    Image Upload 50
  58. What are the 5 Structure(Architecture) Possible for OSes
    1 --> Monolithic 

    2 --> Layered

    3 --> Modular

    4 --> Hybrid

    5 --> Microkernel
  59. System Calls Parameters passing
    There are 3 main System Calls Parameter Passing
    • 1 --> Simplest: Passing the parameter directly to the registers, but it might happen that we have more parameters than registers.
    • 2--> Storing the parameters in a block or table in memory, and then passing the address of that memory block to the register
    • 3--> Using a stack, pushing the parameters onto the stack by the user program, and the stack getting popped by the  OS.
  60. System Call Sequence to Copy from one file to another
    AWAAWAOICILRWUCWT
    • Acquire Input file name
    •   Write Prompt to screen
    •   Accept Input
    • Acquire the Output file name
    •   Write Prompt on the screen 
    •   Accept Input 
    • Open input file
    •   if the file doesn't exist, abort
    • Create output file
    •   if file exists abort
    • Loop
    •   Read from the input file
    •   Write to the output file
    • Until read fails
    • Close output file
    • Write completion message
    • Terminate
  61. Virtualization
    Allows OSes to run applications within other OSes. It is a technique used in computing to create a virtual version of something, such as a computer, an operating system, or an application. This virtual version behaves like the real thing, but it is actually a software-based representation of it.
  62. Computing Environment: Cloud Computing
    Delivers computing, storage, and even apps as a service across a network

    Image Upload 52
  63. Computing Environment:
    Peer-to-Peer Computing
    Every client is connected to every client and they share data that way

    Image Upload 54
  64. Computing Environment:

    Client Server
    Server --> Network -->(Branches to ) many clients

    Image Upload 56
  65. Clustered System
    Much like a multiprocessor: it is multiple computer work at the same time that shares the  same Storage called Storage-Area Network

    • Image Upload 58
  66. Non-Uniform Memory Access (NUMA) :
    Image Upload 60
  67. Definition

    • CPU-
    • Processor-
    • Core-
    • Multicore-
    • Multiprocessor-
    • CPU-The hardware that executes instructions.
    • Processor -A physical chip that contains one or more CPUs.
    • Core-The basic computation unit of the CPU.
    • Multicore-Including multiple computing cores on the same CPU
    • Multiprocessor-Including multiple processors.
  68. Dual Core Design
    It's on a Processor Level
    Image Upload 62
  69. The are 2 types of Multi-Processor architectures:
    • 1) Symmetric Architecture : Shared Memory
    • Image Upload 64

    2) Assymetric : non shared memory
  70. Multiprocessors Advantage known also as  parallel systems, tightly-coupled systems
    • Increase throughput 
    • Economy of Scale
    • Fault Tolerance
  71. Storage Device Hierarchy:
    The are 3
    • 1 Primary Storage: 
    •    -Register
    •    -Cache
    •    -Main Memory
    • 2 Secondary Storage:
    •    -Non Volatile memory
    •    -hard disk
    • 3 Tertiary Storage:
    •    - Optical Disk
    •    - Magnetic Tapes
  72. A ---(1)--- is a software (interface) that enables the operating system (kernel) to communicate with and device controller to control hardware device.
    Device Driver
  73. ---- (1) --- copying information into faster storage system;-- (2) ---can be viewed as a ---- (3) ---  for secondary storage
    • (1) Caching
    • (2) Main Memory
    • (3) Cache
  74. Faster and nonvolatile compared to magnetic disks
    Use various technologies
    SSD: Solid State Disk
  75. Magnetic Disks
    • The other layer of storage
    • Surfaces are divided into tracks further subdivided into sectors
    • Disk controller manages logical interaction between device and computer
  76. Secondary Storage
    • Extension of The main Memory
    • Provide large Nonvolatile memory
  77. The only large storage media directly accessible by the CPU
    Random access
    Typically volatile
    Main Memory
  78. Main Memory
    • The only large storage media directly accessible by the CPU
    • Random access
    • Typically volatile
  79. 1 KB (kilobyte):(1)
    1 MB (megabyte):(2)
    1 GB (gigabyte): (3)
    1 TB (terabyte): (4)
    1 PB (petabyte): (5)
    • (1): 2^10 bytes
    • (2):2^20 bytes
    • (3):2^30 bytes
    • (4):2^40 bytes
    • (5):2^50 bytes
  80. Computer Storage :
    Bit: (1)
    Byte: (2)
    Word:(3)
    • (1) a single binary digit (0 or 1)
    • (2) a collection of 8 bits
    • (3) a fixed-size group of bytes, typically based on the CPU's architecture
  81. Used for high-speed I/O devices that enable data transfer at near-memory speeds. It allows a device controller to transfer data blocks from buffer storage to main memory without CPU intervention, reducing overhead. DMA generates one interrupt per block instead of per byte, improving efficiency.
    Direct Memory Access (DMA)
  82. Transition From user to Kernel Mode
    Image Upload 66
  83. ---(1)--- operation, consisting of user mode and kernel mode, helps protect an OS and system components. A hardware-provided  ---- (2)---- differentiates between user and kernel code execution. Privileged instructions are only executable in kernel mode, while the system calls to switch to kernel mode and return to user mode afterward.
    (1):  Dual-mode

    (2): mode bit
  84. Process Scheduling queueing diagram (There is 2 versions)
    Start with Ready Queue ---> CPU
    Image Upload 68



    Image Upload 70
  85. Process State Graph
    Image Upload 72
  86. Interrupt Driven I/O Cycle Diagram
    Image Upload 74
  87. * Selects a process from the processes in memory that are ready to execute
    * Allocates the CPU to that process
    * Determines which process to run next, based on scheduling algorithm and process priority levels
    CPU Scheduler
  88. special instruction to invoke the OS, by generating an interrupt, to perform an OS-related service


    Or 


    Interface to the services provided by OS
    System Calls
  89. * Contains the address of the instruction to be executed next by the CPU
    * A hardware CPU register

    * The interrupt hardware architecture automatically saves PC value whenever an interrupt occurs
    Program counter
  90. *Stores important system information about each process
    *Includes process state, program counter, CPU registers, and memory management information
    *Used by the operating system to manage and schedule processes
    PCB, process control block
  91. * Identifies the type of interrupt
    * Used as an index into the interrupt vector
    * Looks up the address of the service routine for each interrupt
    Interrupt number
  92. A system bus connects the major components of a computer system, including:
    data bus: to carry information

    address bus: to determine where it should be sent or read from

    control bus: to determine its operation

    Image Upload 76
  93. Device controller informs CPU that it has finished its operation by
    causing an -------
    interrupt
  94. The device driver for each device moves data from/to ---(1)---
    to/from ---(2)---
    (1) main memory

    (2) local buffers
  95. Computer Syst Orginization: One or more CPUs and device controllers connect through a common bus providing access to shared memory. What is the graph
    Image Upload 78
  96. “The one program running at all times on the computer” Other might be system program or Application program
    is the kernel.
  97. Some computers have little or no user interface, we find them in cars and microwaves ...
    Embedded system
  98. Computer System Diagram
    Image Upload 80
  99. Computer System Components
    1. Hardware: provides basic computing resources like CPU, memory, and I/O devices.

    2. Operating system: controls and coordinates the use of the hardware among various applications and users.

    3. Application programs: define the ways in which the system resources are used to solve computing problems like word processors, compilers, web browsers, database systems, and video games.

    4. Users: refer to people, machines, and other computers that interact with the system.
Author
Cr7mlc
ID
361348
Card Set
Operating System
Description
Updated