10.3 Process Management

Another important resource that an operating system must manage is the use of the CPU by individual processes. To understand how an operating system manages processes, we must recognize the stages that a process goes through during its computational life and understand the information that must be managed to keep a process working correctly in a computer system.

The Process States

Processes move through specific states as they are managed in a computer system. That is, a process enters the system, is ready to be executed, is executing, is waiting for a resource, or is finished. FIGURE 10.9 depicts these process states. In the figure, each box represents a state a process might be in, and the arrows indicate how and why a process might move from one state to another.

A figure depicts the process life cycle.

FIGURE 10.9 The process life cycle

Let’s examine what is happing to a process in each state.

  • In the new state, a process is being created. It may, for instance, be a login process created by a user logging onto a timesharing system, an application process created when a user submits a program for execution, or a system process created by the operating system to accomplish a specific system task.

  • A process that has no barriers to its execution is in the ready state. A process in the ready state is not waiting for an event to occur or for data to be brought in from secondary memory. Instead, it is waiting for its chance to use the CPU.

  • A process in the running state is currently being executed by the CPU. Its instructions are being processed in the fetch–execute cycle.

  • A process in the waiting state is currently waiting for resources (other than the CPU). For example, a process in the waiting state may be waiting for a page of its memory to be brought in from secondary memory or for another process to send it a signal that it may continue.

  • A process in the terminated state has completed its execution and is no longer active. At this point the operating system no longer needs to maintain the information regarding the process.

Note that many processes may be in the ready state or the waiting state at the same time, but only one process can be in the running state.

After a process is created, the operating system admits it to the ready state. When the CPU-scheduling algorithm dictates, a process is dispatched to the running state. (CPU scheduling is discussed in more detail in Section 10.4.)

While running, the process might be interrupted by the operating system to allow another process to have its chance on the CPU. In that case, the process simply returns to the ready state. Alternatively, a running process might request a resource that is not available or require I/O to retrieve a newly referenced part of the process, in which case it is moved to the waiting state. A running process may finally get enough CPU time to complete its processing and terminate normally; otherwise, it may generate an unrecoverable error and terminate abnormally.

When a waiting process gets the resource it is waiting for, it moves to the ready state again.

The Process Control Block

The operating system must manage a large amount of data for each active process. Usually this data is stored in a data structure called a process control block (PCB). Generally, each state is represented by a list of PCBs, one for each process in that state. When a process moves from one state to another, its corresponding PCB moves from one state list to another in the operating system. A new PCB is created when a process is first created (the new state) and persists until the process terminates.

The PCB stores a variety of information about the process, including the current value of the program counter, which indicates the instruction in the process that is to be executed next. As the life cycle in Figure 10.8 indicates, a process may be interrupted many times during its execution. At each point, its program counter must be stored so that the next time the process gets into the running state it can pick up where it left off.

The PCB also stores the values of all other CPU registers for that process. Keep in mind that there is only one CPU and therefore only one set of CPU registers. These registers contain the values for the currently executing process (the one in the running state). Each time a process moves to the running state, the register values for the currently running process are stored into its PCB, and the register values of the new running state are loaded into the CPU. This exchange of information is called a context switch.

The PCB also maintains information about CPU scheduling, such as the priority that a process is given by the operating system. It contains memory management information as well, such as base and bound register values (for partitions) or page tables (for paged systems). Finally, the PCB holds accounting information, such as account numbers, time limits, and the amount of CPU time used so far.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.82.167