CH3 Processes PDF
Document Details

Uploaded by EruditeVorticism1110
University of Sharjah
Tags
Summary
This document provides an overview of computer processes, covering topics such as process states, process control blocks (PCBs), and different types of process schedulers. It also details process queues, including job, ready, and device queues. Further, the document explains the differences between I/O-bound and CPU-bound processes.
Full Transcript
Here's a structured markdown representation of the provided text, with formatting for better readability and clarity. ## CH3 - Processes **Terms:** * **Uniprogramming:** One process loaded to RAM. * **Multiprogramming:** Multiple processes loaded to RAM. * **Multitasking:** Multiple process...
Here's a structured markdown representation of the provided text, with formatting for better readability and clarity. ## CH3 - Processes **Terms:** * **Uniprogramming:** One process loaded to RAM. * **Multiprogramming:** Multiple processes loaded to RAM. * **Multitasking:** Multiple processes executing in RAM from different users. * **Multiprocessing:** Multiple CPUs or multiple microprocessors that execute multiple processes. * **Multithreading:** One process contains multiple threads. * **Batch system:** Executes different types of programs. * **Time-shared system:** Handles user programs or tasks. **What is a process?** * A program in execution, it executes sequentially. * Is active. **What is a program?** * Is passive. * Stored on disks (executable file). How are programs executed? * Using GUI, mouse clicks, or command-line entry. * Note: We can have one program that has multiple processes. **After Loading program into memory, what happens to process in Memory?** Process contains Multiple parts: * **Stack**: Stores local variable and parameters in function calls temporarily. * **Heap:** Dynamically allocates memory for local variables stored in Stack. * **Data:** Stores global variables * Initialized data: `int x = 15;` * Uninitialized data: `int x;` * **Text:** Store the whole program code. * Note: Stack + Heap dynamically grows and shrinks based on calls and returns. **With each process being executed, what block does it have that helps executing the process efficiently?** PCB (Process Control Block or Task Control Block): * Stores all info about a process. * Multiple parts: * Process State: Tells the state of the process; running, waiting, etc. * Process number: Process identification (Unique number of process). * Program counter: Location of next instruction being executed. * CPU registers: Stores process-specific data. * CPU scheduling information: Priority, scheduling queue. * Memory limits: Memory-management information (memory allocated to the process). * List of open files. * Accounting information: CPU usage, clock time, time limit. * I/O status information: Tracks I/O devices allocated to process and list of open files. **First part of the PCB block is?** 1. Process state: We have 5 states: * New: A process is created. * Ready: A process is waiting to be assigned to a processor. * Running: A process is being executed. * Waiting: Process is waiting for an event to occur. * Termination: A process finished executing. ## Process Scheduling * Every process waits in the ready state until the scheduler dispatches it for execution. **What are the types of process scheduling queue?** 1. Job queue: It contains all processes in the system (in memory or disk). 2. Ready queue: It contains all processes loaded in main memory and waiting to be dispatched. It stays in the queue until the scheduler dispatches for execution. 3. Device queue: It contains all processes that are waiting for I/O. The process sends a request, then it's put in the device queue, and when the I/O is completed, then it's returned to ready queue. **What are the types of process schedulers?** 1. Short-term (CPU scheduler): * Decides which process should execute next and allocate the CPU. * Fast (milliseconds). * Invoked frequently because when it executes, process things can happen: * Finish executing * Time slice * Higher priority process * So it needs to work fast to keep CPU busy. 2. Long-term (Job scheduler): * Selects which process to put in the ready queue. * Slow (seconds, minutes). * Infrequently invoked because it only runs when a process is brought to the ready queue. 3. Medium-term: * It decreases the degree of multiprogramming by performing swapping, which means: 1. Removing a process from memory. 2. Store on disk. 3. Bring a process back to memory to continue execution. * It does swapping to decrease the load on the memory and create space in RAM. **So, long-term scheduler facts:** * It has a process mix, balancing I/O and CPU bound processes. **So what will happen if one was more than the other?** 1. If only I/O bound processes, the ready queue will be empty, and I/O processes will spend more time waiting (low utilization of CPU). 2. If only CPU bound processes, the ready queue will be loaded, and the I/O queue will remain unused and empty (high utilization of CPU). **How can a process be described?** 1. I/O bound process: * Process spends more time waiting for I/O. * It has short CPU bursts, which means it uses the CPU for a short period of time. 2. CPU bound process: * Process spends more time doing computations. * It has few but long CPU bursts, which means it uses the CPU for a long time. **What is context switching?** Context switching is switching from one process to another. It happens by the CPU saving the state of the current process into its PCB, and the CPU loads the state of the new process from its PCB to start. * The time taken for the process to occur is time overhead which means it does not do useful work while switching. → important fact more complex OS and PCB the longer that context switching takes Flow Chart: **Diagram of process states:** **1.First flow** *"New" -> "Ready":* *"Ready" -> "Running":* scheduler dispatches *"Running" -> "Terminated":* **2.Second flow** *"Running" -> "Ready":* interrupt **3.Third flow** *"Running" -> "Waiting":* I/O or event. *"Waiting" -> "Ready":* I/O or event completion. **Process Scheduling Diagram:** *(The states are New, Ready, Running, Waiting, and Terminated)* * New -> Ready * Ready -> Running * Running -> Terminated * Running -> Ready * Running -> Waiting * Waiting -> Ready ## Operations On Process * **Process Creation:** * Parent process creates child processes, forming a tree. * Processes identified and managed via PID (Process Identifier). * Options in resource sharing, execution, and address space. * Resource sharing options: 1. Parent and children share all resources. 2. Children inherit a subset of parent's resources. 3. Parent and children don't share any resources (independent resources).* * Execution options: 1. Parent and children execute concurrently (multitasking). 2. Parent waits until children execute and terminate, then resumes. * Address space options: 1. Children duplicate of Parent 2. Children has a program loaded in it * **Process Termination:** Terminates Replaces parent process with child process * Types of Termination: 1. Process finishes executing, calls the exit system call to notify OS to delete it. * OS deallocates resources. 2. Child process calls the exit system call, returns the status of child to parent. 3. Parent process terminates, child process terminates by calling the abort system call for several reasons: * Child process exceeds resources allocated. * Task assigned to child process is no longer needed. * Parent process exits, causing the child process to terminate along with it. *(cascading termination, initiated by the OS)* *Zombie:* When the child terminates and there is no parent waiting, the process becomes a zombie. *Orphan:* When the parent terminates and does not invoke the wait call, the children process becomes an orphan. * **Process Communication:** A process can communicate in several ways: * Independent: * Process cannot affect or be affected by the execution of any process. * Cooperating: * Process can affect and be affected by the execution of any process for: 1. Modularity 2. Computation speed up. 3. Convenience 4. Information sharing * Cooperating processes need Interprocess communication (IPC). ### Interprocess Communication Two models: 1. Shared Memory * Communication method for cooperating processes through a shared memory region. * Facts: * Hard to implement, difficult to set up. * Fast (requires a system call to establish the shared memory, but but not to exchange data). * Use large data on the same system. * Process is user controlled, not OS. * Lacks synchronization in action when accessing shared memory region. 2. Message Passing * Communication method where cooperating processes exchange data. * Facts: * Easy to implement. * Slow because it uses system calls to exchange data due to kernel intervention). * Use small data across multiple systems. * Is used for processes to communicate, and has synchronization action * They don't have shared variables when communicating. * Can the message size be fixed or variable * This has 2 facilities Send/Receive * How are communication links implemented? (to do `send()` and `receive()` operations): 1. Direct Communication * Processes must explicitly know their names. * P must know receiver name. * Q must know sender name. * Properties: * Links are automatically established. * Link can only be associated with one pair. * One communication link per pair. * Link can be unidirectional, but usually bidirectional. 2. Indirect Communication * Processes direct & receive messages through mailbox (port). * Each mailbox (port) has a unique ID. * Processes can communicate through shared mailboxes. * Properties: * Links are established through shared mailboxes. * Link can be associated with several processes. * Each pair can have several communication links. * Link can be unidirectional or bidirectional. * Synchronization: * Blocking (Synchronous) * *Blocking send:* The sender is blocked until the message is received. * *Blocking receive:* The receiver is blocked until a valid message is available. * Non-blocking (Asynchronous) * *Non-blocking send:* The sender sends the message and continues * *Non-blocking receive:* The receiver receives a valid message or a NULL message. * Combination: Both can be blocking; this is called rendezvous. * Buffering: * What is buffering?: A queue of messages attached to a link. * How it can be implemented? * Zero capacity: Sender must wait for the receiver to accept the message. * Bounded capacity: Finite length of n messages; sender waits if link is full until it can send. * Unbounded capacity: Infinite length of messages; sender never waits. * Bounded buffer - fixed sized of the buffer * No size limite to eh Buffer * Unbounded buffer * Fixed sized of buffer. * The Producer-consumer example is a paradigm (pattern). * Producer process produces info and it's consumed by consumer process.