3.3 Process States

During a process' execution, the process's state changes. The state of the process is the current condition or status of the process. In the UNIX environment, a process can be in the following states:

  • running

  • runnable (ready)

  • zombied

  • waiting (blocked)

  • stopped

The process changes its state when certain circumstances created by the process or the operating system exist. The state transition is the circumstance that causes the process to change its state. Figure 3-4 is the state diagram for the UNIX environment. The state diagram has nodes and directed edges between the nodes. Each node represents the state of the process. The directed edges between the nodes are state transitions . Table 3-1 lists the state transitions with a brief description. As Figure 3-4 and Table 3-1 show, only certain transitions are allowed between states. For example, there is a transition, an edge, between ready and running but there is no transition between sleeping and running, meaning there are circumstances that cause a process to move from the ready state to the running state but there are no circumstances that cause a process to move from the sleeping state to a running state.

Figure 3-4. The process states and transitions in the UNIX/Linux environments.

graphics/03fig04.gif

When a process is created, it is ready to execute its instructions but must first wait until the processor is available. Each process is only allowed to use a processor for a discrete interval called a time slice . Processes waiting to use a processor are placed in a ready queues. Only processes in the ready queues are selected (by the scheduler) to use the processor. Processes in the ready queues are runnable . When the processor is available, a runnable process is assigned a processor by the dispatcher. When the time slice has expired , the process is removed from the processor, whether it has finished executing all its instructions or not. The process is placed back in the ready queue to wait for its next turn to use the processor. A new process is selected from a ready queue and is given its time slice to execute. System processes are not preempted. When they are given the processor, they run until completion. If the time slice has not expired, a process may voluntarily give up the processor if it cannot continue to execute. The process may have made a request to access an I/O device by making a system call or it may need to wait on a synchronization variable to be released. Processes that cannot continue to execute because they are waiting for an event to occur are in a sleeping state . They are placed in a queue with other sleeping processes. They are removed from that queue and placed back in the ready queue when the event occurrs. The processor may be taken away from a process before its time slice has run out if a process with a higher priority, like a system process, is runnable. The preempted process is still runnable and therfore placed back in the ready queue.

Table 3-1. Process Transitions

State transitions

Descriptions

READY RUNNING (dispatch)

The process is assigned to the processor.

RUNNING READY (timer runout)

The time slice the process is assigned to the processor has run out. The process is placed back in the ready queue.

RUNNING READY ( preempt )

The process has been preempted before the time slice ran out. This can occur if a process with a higher priority is runnable. The process is placed back in the ready queue.

RUNNING SLEEPING (block)

The process gives up the processor before the time slice has run out. The process may need to wait for an event or has made a system call, for example, a request for I/O. The process is placed in a queue with other sleeping processes.

SLEEPING READY (unblock)

The event the process was waiting for has occured or the system call has completed, for example, I/O request is filled. The process is placed back in the ready queue.

RUNNING STOPPED

The process gives up the processor because it has received a signal to stop.

STOPPED READY

The process has received the signal to continue and is placed back in the ready queue.

RUNNING ZOMBIED

The process has been terminated and awaits the parent to retrieve its exit status from the process table.

ZOMBIED EXIT

The parent process has retrieved the exit status and the process exits the system.

RUNNING EXIT

The process has terminated, the parent has retrieved the exit status, and the process exits the system.

A running process can receive a signal to stop executing. The stopped state is different from a sleeping state because the time slice has not expired nor has the process made any requests of the system. The process may receive a signal to stop because it is being debugged or some situation in the system has occured. The process makes a transition from running state to stopped state . Later, the process may be awakened or destroyed .

When a process has executed all its instructions, it exits the system. The process is removed from the process table, the PCB is destroyed, and all of its resources are deallocated and returned to the system pool of available resources. A process that is unable to continue executing and cannot exit the system is zombied . A zombied process does not use any system resources but it still maintains an entry in the process table. When the process tables contain too many zombied processes, the performance of the system is affected, which can possibly cause the system to reboot.



Parallel and Distributed Programming Using C++
Parallel and Distributed Programming Using C++
ISBN: 0131013769
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net