Process - definition, relationship and state diagram
Process management involves the execution of programs as processes, requiring efficient management of resources by the operating system. It includes activities such as scheduling, creating, and synchronizing processes, which transition through various states like new, ready, running, blocked, and terminated. The operating system maintains a process control block (PCB) for each process, containing essential attributes and state information.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views
Process - definition, relationship and state diagram
Process management involves the execution of programs as processes, requiring efficient management of resources by the operating system. It includes activities such as scheduling, creating, and synchronizing processes, which transition through various states like new, ready, running, blocked, and terminated. The operating system maintains a process control block (PCB) for each process, containing essential attributes and state information.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20
Process & Process management
What is Process Management?
• A Program does nothing unless its instructions are executed by a CPU. A program in execution is called a process. In order to accomplish its task, process needs the computer resources. • There may exist more than one process in the system which may require the same resource at the same time. Therefore, the operating system has to manage all the processes and the resources in a convenient and efficient way. • Some resources may need to be executed by one process at one time to maintain the consistency otherwise the system can become inconsistent and deadlock may occur. • So, In an operating system, a process is a program that is being executed. The operating system is responsible for the following activities in connection with Process Management: • Scheduling processes and threads on the CPUs. • Creating and deleting both user and system processes. • Suspending and resuming processes. • Providing mechanisms for process synchronization. • Providing mechanisms for process communication. Process synchronization: It is the coordination of multiple processes that share re-sources in an operating system. It ensures that processes execute in a controlled manner and access shared resources without problem. Attributes of a process The Attributes of the process are used by the Operating System to create the process control block (PCB) for each of them. This is also called context of the process. Attributes which are stored in the PCB are described below: 1. Process ID: When a process is created, a unique id is assigned to the process which is used for unique identification of the process in the system. 2. Program counter: A program counter stores the address of the last instruction of the process on which the process was suspended. The CPU uses this address when the execution of this process is resumed. 3. Process State: The Process, from its creation to the completion, goes through various states which are new, ready, running and waiting. 4. Priority: Every process has its own priority. The process with the highest priority among the processes gets the CPU first. This is also stored on the process control block. 5. General Purpose Registers: Every process has its own set of registers which are used to hold the data which is generated during the execution of the process. 6. List of open files: During the Execution, Every process uses some files which need to be present in the main memory. OS also maintains a list of open files in the PCB. 7. List of open devices: OS also maintain the list of all open devices which are used during the execution of the process. Process States: State Diagram The process, from its creation to completion, passes through various states. The minimum number of states is five. The names of the states are not standardized although the process may be in one of the following states during execution. • The Two-State Model: The simplest way to think about a process’s lifecycle is with just two states: 1. Running: This means the process is actively using the CPU to do its work. 2. Not Running: This means the process is not currently using the CPU. It could be waiting for something, like user input or data, or it might just be paused. • When a new process is created, it starts in the not running state. Initially, this process is kept in a program called the dispatcher.
Here’s what happens step by step:
1. Not Running State: When the process is first created, it is not using the CPU. 2. Dispatcher Role: The dispatcher checks if the CPU is free (available for use). 3. Moving to Running State: If the CPU is free, the dispatcher lets the process use the CPU, and it moves into the running state. 4. CPU Scheduler Role: When the CPU is available, the CPU scheduler decides which process gets to run next. It picks the process based on a set of rules called the scheduling scheme, which varies from one operating system to another. • The Five-State Model: The five-state process lifecycle is an expanded version of the two-state model. The two-state model works well when all processes in the not running state are ready to run. However, in some operating systems, a process may not be able to run because it is waiting for something, like input or data from an external device. To handle this situation better, the not running state is divided into two separate states: A simple explanation of the five-state process model: • New: This state represents a newly created process that hasn’t started running yet. It has not been loaded into the main memory, but its process control block (PCB) has been created, which holds important information about the process. • Ready: A process in this state is ready to run as soon as the CPU becomes available. It is waiting for the operating system to give it a chance to execute. • Running: This state means the process is currently being executed by the CPU. Since we’re assuming there is only one CPU, at any time, only one process can be in this state. • Blocked/Waiting: This state means the process cannot continue executing right now. It is waiting for some event to happen, like the completion of an input/output operation (for example, reading data from a disk). • Exit/Terminate: A process in this state has finished its execution or has been stopped by the user for some reason. At this point, it is released by the operating system and removed from memory. • The Seven-State Model: • Block or Wait State: If a process requires an Input/output operation or a blocked resource during execution, it changes from run to block or the wait state. The process advances to the ready state after the I/O operation is completed or the resource becomes available. • Suspend Ready State: If a process with a higher priority needs to be executed while the main memory is full, the process goes from ready to suspend ready state. Moving a lower-priority process from the ready state to the suspend ready state frees up space in the ready state for a higher- priority process. Until the main memory becomes available, the process stays in the suspend-ready state. The process is brought to its ready state when the main memory becomes accessible. • Suspend Wait State: If a process with a higher priority needs to be executed while the main memory is full, the process goes from the wait state to the suspend wait state. Moving a lower- priority process from the wait state to the suspend wait state frees up space in the wait state for a higher-priority process. The process gets moved to the suspend-ready state once the resource becomes accessible. The process is shifted to the ready state once the main memory is available. Note – 01: • A process must pass through at least four states. • A process must go through a minimum of four states to be considered complete. • The new state, run state, ready state, and terminate state are the four states. • However, in case a process also requires I/O, the minimum number of states required is 5. Note – 02: • Only one process can run at a time on a single CPU. • Any processor can only handle one process at a time. • When there are n processors in a system, only n processes can run at the same time. Note – 03: • Present in Memory : State • Secondary Memory: New state • Main Memory: Ready state • Main Memory: Run state • Main Memory: Wait state • Secondary Memory: Suspend wait state • Secondary Memory: Suspend ready state Note – 04: • It is much more preferable to move a given process from its wait state to its suspend wait state. • Consider the situation where a high-priority process comes, and the main memory is full. • Then there are two options for making space for it. They are: • Suspending the processes that have lesser priority than the ready state. • Transferring the lower-priority processes from wait to the suspend wait state. • Now, out of these: • Moving a process from a wait state to a suspend wait state is the superior option. • It is because this process is waiting already for a resource that is currently unavailable. How Does a Process Move From One State to Other State?
A process can move between different states in an operating
system based on its execution status and resource availability: • New to Ready: When a process is created, it is in a new state. It moves to the ready state when the operating system has allocated resources to it and it is ready to be executed. • Ready to Running: When the CPU becomes available, the operating system selects a process from the ready queue depending on various scheduling algorithms and moves it to the running state. • Running to Blocked: When a process needs to wait for an event to occur (I/O operation or system call), it moves to the blocked state. For example, if a process needs to wait for user input, it moves to the blocked state until the user provides the input. • Running to Ready: When a running process is preempted by the operating system, it moves to the ready state. For example, if a higher-priority process becomes ready, the operating system may preempt the running process and move it to the ready state. • Blocked to Ready: When the event a blocked process was waiting for occurs, the process moves to the ready state. For example, if a process was waiting for user input and the input is provided, it moves to the ready state. • Running to Terminated: When a process completes its execution or is terminated by the operating system, it moves to the terminated state. Types of Schedulers: • Long-Term Scheduler: Decides how many processes should be made to stay in the ready state. This decides the degree of multiprogramming. Once a decision is taken it lasts for a long time which also indicates that it runs infrequently. Hence it is called a long-term scheduler. Multiprogramming : We have many processes ready to run. There are two types of multiprogramming: • Preemption: Process is forcefully removed from CPU. Pre-emption is also called time sharing or multitasking. • Non-Preemption: Processes are not removed until they complete the execution. Once control is given to the CPU for a process execution, till the CPU releases the control by itself, control cannot be taken back forcibly from the CPU. Degree of Multiprogramming : The number of processes that can reside in the ready state at maximum decides the degree of multiprogramming, e.g., if the degree of programming = 100, this means 100 processes can reside in the ready state at maximum. • Short-Term Scheduler: Short-term scheduler will decide which process is to be executed next and then it will call the dispatcher. A dispatcher is a software that moves the process from ready to run and vice versa. In other words, it is context switching. It runs frequently. Short-term scheduler is also called CPU scheduler. • Medium Scheduler: Suspension decision is taken by the medium- term scheduler. The medium-term scheduler is used for swapping which is moving the process from main memory to secondary and vice versa. The swapping is done to reduce degree of multiprogramming.
Context Switching: When the operating system switches from
executing one process to another, it must save the current process’s context and load the context of the next process to execute. This is known as context switching. Features of The Process State: • A process can move from the running state to the waiting state if it needs to wait for a resource to become available. • A process can move from the waiting state to the ready state when the resource it was waiting for becomes available. • A process can move from the ready state to the running state when it is selected by the operating system for execution. • The scheduling algorithm used by the operating system determines which process is selected to execute from the ready state. • The operating system may also move a process from the running state to the ready state to allow other processes to execute. • A process can move from the running state to the terminated state when it completes its execution. • A process can move from the waiting state directly to the terminated state if it is aborted or killed by the operating system or another process. • A process can go through ready, running and waiting state any number of times in its lifecycle but new and terminated happens only once. • The process state includes information about the program counter, CPU registers, memory allocation, and other resources used by the process. • The operating system maintains a process control block (PCB) for each process, which contains information about the process state, priority, scheduling information, and other process- related data. • The process state diagram is used to represent the transitions between different states of a process and is an essential concept in process management in operating systems.