CH3-Processes and Process Scheduling PDF

Document Details

EruditeVorticism1110

Uploaded by EruditeVorticism1110

University of Sharjah

Tags

process scheduling operating systems process control block computer science

Summary

This document covers processes and process scheduling. It details the different types of process states, scheduling queues and CPU scheduling. The document also explains the process control block (PCB).

Full Transcript

Okay, I will convert the information from the image into a structured markdown format: ### CH3-Processes **Terms:** * **Uniprogramming:** One process loaded to RAM. * **Multiprogramming:** Multiple processes loaded to RAM. * **Multitasking:** Multiple processes executing in RAM from differe...

Okay, I will convert the information from the image into a structured markdown format: ### 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:** Executes user programs or tasks. **What is a process?** A program in execution; it executes sequentially. **What are the types of process scheduling queues?** 1. **Job queue:** Contains all processes in the system (in memory or disk). 2. **Ready queue:** Contains all processes loaded in main memory and waiting to be dispatched. * New process $\rightarrow$ ready queue. * It stays in the queue until the scheduler dispatches it for execution. 3. **Device queue:** Contains all processes that are waiting for I/O. * The process sends a request, then it's put in the device queue. * After the I/O is completed, then it's returned to ready queue. **What are the types of process schedulers?** * **Short-term (CPU scheduler):** * Decides which process should execute next and allocate CPU. * Fast (millisecond). * Invoked frequently because when it executes, process things can happen: 1. Finish executing. 2. Time slice. 3. Higher priority process. * So it needs to work fast to keep CPU busy. * **Long-term (Job scheduler):** * Selects which processes to put in the ready queue. * Slow (seconds, minutes). * Infrequently invoked because it only runs when a process is brought to the ready queue. * **Medium-term:** * It decreases the degree of multi-programming by performing swapping, which means: 1. Removing processes from memory. 2. Store on disk. 3. Bring processes back to memory to continue execution. * It does swapping to decrease the load on the memory and create space in RAM. **Process Scheduling:** ready $ \rightarrow $ running ``` CPU IVO queue VO request time slice expired child fork ``` **Process:** Program becomes a process when loaded into the memory $\downarrow$ * Is passive * Stored in disk (executable file) * Is active * Found in the main memory **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?** $\downarrow$ **Process contains Multiple parts:** * low memory | | Description | | :---- | :------------------------------------------------------------------------------------ | | Text | Stores the whole program code. | | Data | Stores global variables. | | Initialized Data int x= 15; | | | Uninitialized Data | int x; | Heap | Dynamically allocates memory for local variables Stored in Stack. | | Stack | Stores local variables and parameters in function calls temporarily during run time. | * high memory Note: stack + heap dynamically grows and shrink based on call and returns **With each process being executed what block does it have that helps in executing the process efficiently?** **PCB** * Process control block or task control block * Stores all info about a process. **and how process can be described?** 1. **I/O bound process:** * Process spends more time waiting for I/O. * It has short CPU bursts which means it uses 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 use CPU for a long time **Multiple parts of Process control block:** * 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: priority, scheduling information. * 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 + list of open files. **First part of the PCB block is?** 1. **Process State** * We have 5 states: * New: a process is being created * Ready: a process is waiting to be assigned to a processor * Running: a process is being executed * Waiting: a process is waiting for an event to occur * Termination: a process finished executing **so long term scheduler facts:** * it has a process mix balancing I/O and CPU bound process so what will happen if one was more than the other? 1. if only I/O bound process the ready queue will be empty and I/O processes will spend more time waiting (low utilization of CPU) 2. if only CPU bound process the ready queue will loaded and the I/O queue will remain unused and empty (high utilization of CPU) **What is context switching?** Context switching is switching from one process to another; it happens by the CPU saving the state of current process into its PCB for it to resume later. Then the CPU loads the state of the new process from its PCB to start executing. 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. **Diagrams:** Description of the process state diagram: * **(1) new $\rightarrow$ ready $\rightarrow$ running $\rightarrow$ termination** * schedule * dispatch * the process runs as usual * **(2) new $\rightarrow$ ready $\rightarrow$ running $\rightarrow$ waiting $\rightarrow$ ready** * schedule * dispatch * interrupt * because the process faces an interrupt during running so it stores data in PCB and returns to ready waiting for CPU time. * **(3) new $\rightarrow$ ready $\rightarrow$ running $\rightarrow$ waiting $\rightarrow$ ready** * schedule * dispatch * I/O or event completion * the process needs to wait for user input or I/O device, etc., when it's completed it goes to ready state waiting for CPU time ### Operations On Processes **Process of Creation** * Is when we have a parent process that creates a children process and so on until they form a tree. * We have Options in Resource sharing, Execution, and Address Space. * To identify and manage all the processes we have something called (pid) - process identifier **Resource-sharing options:** 1. Parent and children share all resources. 2. Children inherit 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 executes and terminates 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 * 3 Types of Termination what are they? * When the process finishes executing it calls the exit system call to notify the OS to delete it. * Case 1: The OS deallocates the resources associated with the process * Case 2: it's a child process and it calls the exit system call so it returns the status of child to parent * When the parent process terminates and the children processes terminate by it calling the abort system call for several reasons: 1. The child process exceeds the resource allocated to it. 2. The task assigned to child process is no longer needed. 3. The parent process exits, so the child process terminates along with it. *Cascading termination and it's Initiated by the OS* * Zombie: When the child terminates and there is no parent waiting the process becomes zombie. * Orphan: When the parent terminates and does not invoke the wait call so the children process becomes an orphan **The process can communicate in several ways what are the types of communication in a process?** * May have 2 types of process: independent and cooperating * **independent:** * Process cannot affect or be affected by the execution of ang process. * **cooperating:** * Process can affect and be affected by the execution of any process. Why? Modularity, Computation speed up, Convenience, Information sharing $\downarrow$ Cooperating process needs inter-process communication (IPC) **Interprocess Communication** It has two models: * Shared Memory. * Message passing **What is shared memory?** It is a communication method for multiple processes (cooperating processes) through shared memory region * Facts: * Hard to implement, difficult to setup. * Fast because it requires system calls to establish the shared memory but not to exchange data. * Used for large data on same system. * This process is user control and not OS. **What is message passing?** It's a communication method where cooperating processes exchange data * Facts: * Easy to implement. * Slow because it uses system calls to exchange data because of kernel intervention. * Used for small data across multiple systems. * Used for processes to communicate and they have synchronization in their action. * They don't have shared variables when communicating. * It lacks or requires synchronization in action when accessing the shared memory region * Is the message size can be fixed or variable * It has 2 facilities provided by IPC: send message / receive message * This can be done through communication links **How are communication links implemented?** (to do send() and receive() operations) 1. Direct or indirect communication. 2. Synchronous or asynchronous. 3. Automatic or explicit buffering. | | Direct Communication | Indirect Communication | | :------------ | :------------------------------------------------- | :----------------------------------------------------- | | Description | Process must explicitly know their names. | Processes direct & receive messages through mailbox (port). | | Properties | sender must know receiver name. | each mailbox(port) hass unique id. | | | receiver must know sender name. | Process can communicate through shared mailbox | | Links | Links are automatically established. | Links are established through shared mail boxes | | Pair | Link can only be associated with one pair. | Link can be assosiated with several processes | | Links per Pair | One communication link per pair. | Each pair can have several communication link | | Direction | Link can be unidirectional but usually bidirectional | Unidirectional or Bidirectional | **Synchronization** | | Blocking (synchronous) | Non-blocking (Asynchronous) | | :----------------- | :------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------- | | Blocking send | The sender is blocked until message is received. | Sender send message and continues | | Blocking receive | The receiver is blocked until message is available. | Receiver receives message. | | Message situations | Blocking send and blocking receive can be set for multiple outcomes, this combination is called *rendezvous *. | Non-blocking receive can result in multiple outcomes, returning a valid or a *NULL message*. | **Buffering** * What is buffering? A queue of messages attached to a link. * How it can be implemented? *Zero capacity: sender has to wait for receiver to accept 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.* * Unbounded buffer: no size limit to the buffer * Bounded buffer: fixed size of the buffer \*Producer consumer example or paradigm (pattern):\* \*Producer process produces info and it's consumed by consumer process.\*

Use Quizgecko on...
Browser
Browser