Full Transcript

Process Management Process Management ◼ The operating system is responsible for the following activities in connection with process management. ⚫ Process creation and deletion. ⚫ Process suspension and resumption. ⚫ Provision of mechanisms for:...

Process Management Process Management ◼ The operating system is responsible for the following activities in connection with process management. ⚫ Process creation and deletion. ⚫ Process suspension and resumption. ⚫ Provision of mechanisms for: ◼ process synchronization ◼ process communication ◼ The OS is also responsible for allocating and scheduling resources for the processes. Multiprogramming Multiprogramming or multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as CPU. Multiprogramming is a technique used to utilize maximum CPU time by running multiple programs simultaneously. Multiprogramming systems are designed to maximize CPU usage. Process vs Program ◼ Program – a set of instructions that can be executed by a computer ◼ A computer may store a number of different programs in its memory. ◼ Programs are put into a storage area accessible to the computer ◼ Programs are static and passive Process vs Program ◼ A process is a sequence of interdependent and linked procedures which, at every stage, consume one or more resources (CPU time, memory, i/o devices). ◼ A process is an execution instance of a program ◼ Processes are active and dynamic ⚫ Child process – is a process created by the main process DIFFERENCE BETWEEN PROGRAM AND PROCESS No. Program Process Program contains a set of Process is an instance of an 1. instructions designed to complete a executing program. specific task. Process is a active entity as it is Program is a passive entity as it 2. created during execution and loaded resides in the secondary memory. into the main memory. Process exists for a limited span of Program exists at a single place and 3. time as it gets terminated after the continues to exist until it is deleted. completion of task. 4. Program is a static entity. Process is a dynamic entity. DIFFERENCE BETWEEN PROGRAM AND PROCESS (cont.) No. Program Process Program does not have any Process has a high resource resource requirement, it only requirement, it needs resources like 5. requires memory space for CPU, memory address, I/O during storing the instructions. its lifetime. Program does not have any Process has its own control block 6. control block. called Process Control Block. In addition to program data, a Program has two logical process also requires additional 7. components: code and data. information required for the management and execution. Many processes may execute a single program. There program code 8. Program does not change itself. may be the same but program data may be different. these are never same. The States of a Process Process State Diagram The States of a Process ◼ Created or New - When a process is first created, it occupies the "created" or "new" state. ◼ In this state, the process awaits admission to the "ready" state. ◼ This admission will be approved or delayed by a long-term or admission scheduler. The Process States ◼ Ready or runnable - A "ready" or "waiting" process has been loaded into main memory and is awaiting execution on a CPU. ◼ There may be many "ready" processes at any one point of the systems execution ◼ Processes that are ready for the CPU are kept in a queue for "ready" processes. The Process States ◼ Running - A "running", "executing" or "active" process is a process which is currently executing on a CPU. ◼ From this state the process may exceed its allocated time slice and be swapped out and back to "ready" by the operating system. ◼ it may also indicate that it has finished and be terminated or it may block on some needed resource (such as an input / output resource) and be moved to a "blocked" state. The Process States ◼ Waiting - The process is waiting for the allocation of CPU time and other resources for execution. ◼ If the process needs to stop running for some reason, it enters the waiting state. ◼ When a process waits for a certain resource to be assigned or for input from the user then the OS move this process to the block or wait state and assigns the CPU to the other processes. The Process States ◼ Terminated - A process may be terminated, either from the "running" state by completing its execution or by explicitly being killed. ◼ In either of these cases, the process moves to the "terminated" state. ◼ If a process is not removed from memory after entering this state, this state may also be called zombie. The Process Control Block ◼ A Process Control Block (PCB, also called Task Control Block or Task Struct) is a data structure in the operating system kernel containing the information needed to manage a particular process. ◼ The PCB is "the manifestation of a process in an operating system" ◼ Processes are represented by PCBs or process descriptors Process Control Block ◼ The PCB contains important information about the specific process including: ⚫ The current state of the process i.e., whether it is ready, running, waiting, or whatever. ⚫ Unique identification of the process in order to track "which is which" information (PID) ⚫ A pointer to parent process. ⚫ Similarly, a pointer to child process (if it exists). ⚫ The priority of process (a part of CPU scheduling information). ⚫ Pointers to locate memory of processes. ⚫ A register save area. ⚫ The processor it is running on. ⚫ I/O Information (i.e. I/O devices allocated to this process, list of opened files, etc) Seatwork / Activity 1. What are the attributes that a Process Control Block contains? 2. Discuss each field of PCB in detail. 3. How is process scheduling done using a process control block? 4. How does the process control block help in resource allocation? 5. What is the impact of process termination on the process control block? Structure of a PCB Process state Process number Program counter Registers Memory limits List of open files …… Location of the PCB ◼ Since the PCB contains the critical information for the process, it must be kept in an area of memory protected from normal user access. ◼ In some operating systems the PCB is placed at the beginning of the kernel stack of the process. Context Switching ◼ The act of reassigning a CPU from one task to another one is called a context switch. ◼ A context switch occurs when the kernel transfers control of the CPU from an executing process to another that is ready to run. Context Switching ◼ The context is the set of CPU register values and other data that describes the process' state. ◼ The kernel first saves the context of the process then loads the context of the new process which then starts to execute. Context Switching ◼ A process runs on the CPU until it is context switched. This happens when one of the following occurs: ⚫ The process exits. ⚫ The process uses up its time slice. ⚫ The process requires another resource that is not currently available or needs to wait for I/O to complete. ⚫ A resource has become available for a sleeping process. If there is a higher priority process ready to run, the kernel will run this instead (the current process is preempted). Resource Allocation and Scheduling Concepts RESOURCE ALLOCATION ◼ There are two kinds of resources: ⚫ Pre-emptible resources – Can take resources away, and give them back later – May only have one of these resource – Example: CPU – OS management: scheduling Decide the order in which requests are serviced Decide how long the process keeps resource ⚫ Non-pre-emptible resources – Once given resource, cannot be reused until voluntarily given up – Example: Blocks on disk – OS management: allocation Decide which process gets which resource RESOURCE ALLOCATION ◼ Since resources are limited, techniques must be devised to share them among competing processes. These techniques should: 1. Mutually exclude processes from unshareable resources 2. Prevent deadlock and starvation ◼ Deadlock – two or more processes wait indefinitely for resources held by each other ◼ Starvation – one or more processes never gets a share of the resource 3. Ensure high level of utilization 4. Provide a degree of fairness for all processes SCHEDULING ◼ It is the process of determining or choosing which of the processes in the ready queue runs next. ◼ It can have a big effect on resource utilization and on the overall performance of the system. ◼ Scheduling refers to the way processes are assigned to run on the available CPUs. This assignment is carried out by software known as a scheduler. ◼ The scheduler is the module that moves jobs or processes from queue to queue SCHEDULING ◼ Two major classes of scheduling systems: ⚫ in preemptive systems, the scheduler can interrupt a job and force a context switch ⚫ in non-preemptive systems, the scheduler waits for the running job to explicitly (voluntarily) block or terminate SCHEDULING ◼ CPU scheduling decisions occur when process: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready. 4. Terminates. ◼ Scheduling under 1 and 4 is non- preemptive. ◼ Scheduling under 2 and 3 is preemptive. SCHEDULING ◼ Basic assumptions behind most scheduling algorithms: ⚫ There is a pool of runnable processes contending for the CPU. ⚫ The processes are independent and compete for resources. ◼ The job of the scheduler is to distribute the scarce resource of the CPU to the different processes ``fairly'' (according to some definition of fairness) and in a way that optimizes some performance criteria. SCHEDULING ◼ How do processes behave? ⚫ First, CPU/IO burst cycle. A process will run for a while (the CPU burst), perform some IO (the IO burst), then run for a while more (the next CPU burst). ◼ How long between IO operations? ⚫ Depends on the process ◼ IO Bound processes- processes that perform lots of IO operations. Each IO operation is followed by a short CPU burst to process the IO, then more IO happens. ◼ CPU-bound processes- processes that perform lots of computation and do little IO. Tend to have a few long CPU bursts. Criteria in CPU Scheduling The CPU scheduling is concerned mainly with: ◼ CPU utilization - to keep the CPU as busy as possible. ◼ Throughput - number of processes that complete their execution per time unit. ◼ Turnaround time - interval from the time of submission to time of completion ◼ Waiting time – the amount of time a process has been waiting in the ready queue ◼ Response Time – the amount of time it takes from when a request was submitted until the first response is produced. ◼ Fairness - Equal CPU time to each process. Criteria in CPU Scheduling Frequently, the focus is to: Optimize the average value Optimize minimum and maximum values Minimize variance ◼ maximize CPU utilization ◼ maximize job throughput ◼ minimize job turnaround time ◼ minimize job waiting time ◼ minimize response time ◼ Maximize resource utilization ◼ Keep expensive devices busy ◼ Minimize overhead ◼ Reduce number of context switches ◼ Maximize fairness ⚫ All jobs get same amount of CPU over some time interval Levels of Scheduling ◼ Dispatching or Short-term Scheduling ⚫ The short-term scheduler (also known as the dispatcher) decides which of the ready, in- memory processes are to be executed (allocated a CPU) next. ⚫ The short-term scheduler makes scheduling decisions much more frequently than the long- term or mid-term schedulers - a scheduling decision will at a minimum have to be made after every time slice, and these are very short. ⚫ This scheduler can be preemptive, implying that it is capable of forcibly removing processes from a CPU when it decides to allocate that CPU to another process, or non-preemptive (also known as "voluntary" or "co-operative"), in which case the scheduler is unable to "force" processes off the CPU. Levels of Scheduling ◼ Medium term Scheduling ⚫ The mid-term scheduler temporarily removes processes from main memory and places them on secondary memory (such as a disk drive) or vice versa. This is commonly referred to as "swapping out" or "swapping in“. ⚫ The mid-term scheduler may decide to swap out a process which has not been active for some time, or a process which has a low priority, or a process which is taking up a large amount of memory, swapping the process back in later when more memory is available, or when the process has been unblocked and is no longer waiting for a resource Levels of Scheduling ◼ Long Term Scheduling ⚫ The long-term, or admission scheduler decides which jobs or processes are to be admitted to the ready queue ⚫ When an attempt is made to execute a program, its admission to the set of currently executing processes is either authorized or delayed by the long-term scheduler. ⚫ This scheduler dictates what processes are to run on a system, and the degree of concurrency to be supported at any one time.

Use Quizgecko on...
Browser
Browser