Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

Process State Models

Presentation By M.Hassan REG No: BSCS-013R11-117 Semester BSCS 4th B

Process State
In a multitasking computer system, processes may occupy a variety of states. These distinct states may not actually be recognized as such by the operating system kernel, however they are a useful abstraction for the understanding of processes.

The operating systems principal responsibility is in controlling the execution of processes. This includes determining the interleaving pattern for execution and allocation of resources to processes. One part of designing an OS is to describe the behavior that we would like each process to exhibit.

Two States Process Model


The simplest model is based on the fact that a process is either being executed by a processor or it is not. Thus, a process may be considered to be in one of two states, RUNNING or NOT RUNNING. When the operating system creates a new process, that process is initially labeled as NOT RUNNING, and is placed into a queue in the system in the NOT RUNNING state. The process (or some portion of it) then exists in main memory, and it waits in the queue for an opportunity to be executed. After some period of time, the currently RUNNING process will be interrupted, and moved from the RUNNING state to the NOT RUNNING state, making the processor available for a different process. The dispatch portion of the OS will then select, from the queue of NOT RUNNING processes, one of the waiting processes to transfer to the processor. The chosen process is then relabeled from a NOT RUNNING state to a RUNNING state, and its execution is either begun if it is a new process, or is resumed if it is a process which was interrupted at an earlier time. From this model we can identify some design elements of the OS: The need to represent, and keep track of each process. The state of a process. The queuing of NON RUNNING processes

Two State Process Model


Dispatch

Exit

Enter

Not-Running

Running

Pause

Three State Process Model


Although the two-state process management model is a perfectly valid design for an operating system, the absence of a BLOCKED state means that the processor lies idle when the active process changes from CPU cycles to I/O cycles. This design does not make efficient use of the processor. The three-state process management model is designed to overcome this problem, by introducing a new state called the BLOCKED state. This state describes any process which is waiting for an I/O event to take place. In this case, an I/O event can mean the use of some device or a signal from another process. The three states in this model are: RUNNING: The process that is currently being executed. READY: A process that is queuing and prepared to execute when given the opportunity. BLOCKED: A process that cannot execute until some event occurs, such as the completion of an I/O operation.

Three State Process Model


At any instant, a process is in one and only one of the three states. For a single processor computer, only one process can be in the RUNNING state at any one instant. There can be many processes in the READY and BLOCKED states, and each of these states will have an associated queue for processes. Processes entering the system must go initially into the READY state; processes can only enter the RUNNING state via the READY state. Processes normally leave the system from the RUNNING state. For each of the three states, the process occupies space in main memory. While the reason for most transitions from one state to another might be obvious, some may not be so clear. RUNNING READY the most common reason for this transition is that the running process has reached the maximum allowable time for uninterrupted execution; i.e. timeout occurs. Other reasons can be the imposition of priority levels as determined by the scheduling policy used for the Low Level Scheduler, and the arrival of a higher priority process into the READY state. RUNNING BLOCKED A process is put into the BLOCKED state if it requests something for which it must wait. A request to the OS is usually in the form of a system call, (i.e. a call from the running process to a function that is part of the OS code). For example, requesting a file from disk or a saving a section of code or data from memory to a file on disk.

Three State Process Model


I/0 Completion Enter

Ready

Blocked

Dispatch Time Out Running Exit I/0 Wait

Five State Process Model


The following typical process states are possible on computer systems of all kinds. In most of these states, processes are "stored" on main memory. The five state process model is just like three state process model, it just have two additional states i.e. Created and Terminated. Ready, Blocked and Running will work same as expressed in Three State Process Model. Description of other two is given below Created (Also called 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. Typically in most desktop computer systems, this admission will be approved automatically, however for real-time operating systems this admission may be delayed. In a real time system, admitting too many processes to the "ready" state may lead to oversaturation and over contention for the systems resources, leading to an inability to meet process deadlines. 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, it may become a Zombie process.

Five State Process Model


Created I/0 Completion

Enter

Blocked

Ready
Dispatch Time Out Running Exit Terminated I/0 Wait

Zombie Process
When a process finishes execution, it will have an exit status to report to its parent process. Because of this last little bit of information, the process will remain in the operating systems process table as a zombie process, indicating that it is not to be scheduled for further execution, but that it cannot be completely removed (and its process ID cannot be reused) until it has been determined that the exit status is no longer needed. When a child exits, the parent process will receive a SIGCHLD signal to indicate that one of its children has finished executing; the parent process will typically call the wait() system call at this point. That call will provide the parent with the childs exit status, and will cause the child to be reaped, or removed from the process table. How do I see if there are zombie processes on a system? # top OR # ps aux | awk '{ print $8 " " $2 }' | grep -w Z How do I kill zombie process? You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service. You can kill zombie process using PID obtained from any one of the above command. kill -s SIGCHLD <ppid>

Seven State Process Model


In Seven State Process Model two additional states are available for processes in systems that support virtual memory. In both of these states, processes are "stored" on secondary memory (typically a hard disk). These States are Swapped out and Waiting and Swapped Out and Blocked. Other processes work as in Five State Process Model. There description is : Swapped Out and Waiting (Also called suspended and waiting.) In systems that support virtual memory, a process may be swapped out, that is, removed from main memory and placed in virtual memory by the mid-term scheduler. From here the process may be swapped back into the waiting state. Swapped Out and Blocked (Also called suspended and blocked.) Processes that are blocked may also be swapped out. In this event the process is both swapped out and blocked, and may be swapped back in again under the same circumstances as a swapped out and waiting process (although in this case, the process will move to the blocked state, and may still be waiting for a resource to become available).

Seven State Process Model


Created I/0 Completion Suspended Blocked

Enter

Blocked

Ready
Dispatch Time Out Suspended Ready Running Exit Terminated I/0 Wait

You might also like