A process is more than the program code, which is sometimes known as the text section. It also includes the current activity, as represented by the value of the program counter and the contents of the processor’s registers. A process generally also includes the process stack, which contains temporary data (such as function parameters, return addresses, and local variables), and a data section, which contains global variables. A process may also include a heap, which is memory that is dynamically allocated during process run time
Note that a process itself can be an execution environment for other code. The Java programming environment provides a good example. In most circumstances, an executable Java program is executed within the Java virtual machine (JVM). The JVM executes as a process that interprets the loaded Java code and takes actions (via native machine instructions) on behalf of that code. For example, to run the compiled Java program Program.class, we would enter
The command java runs the JVM as an ordinary process, which in turns executes the Java program Program in the virtual machine. The concept is the same as simulation, except that the code, instead of being written for a different instruction set, is written in the Java language.
As a process executes, it changes state. The state of a process is defined in part by the current activity of that process. A process may be in one of the following states:
- New. The process is being created.
- Running. Instructions are being executed
- Waiting. The process is waiting for some event to occur (such as an I/O completion or reception of a signal)
- Ready. The process is waiting to be assigned to a processor.
- Terminated. The process has finished execution
Process Control Block
It contains many pieces of information associated with a specific process, including these:
- Process state. The state may be new, ready, running, waiting, halted, and so on
- Program counter. The counter indicates the address of the next instruction to be executed for this process.
- CPU registers. The registers vary in number and type, depending on the computer architecture. They include accumulators, index registers, stack pointers, and general-purpose registers, plus any condition-code information. Along with the program counter, this state information must be saved when an interrupt occurs, to allow the process to be continued correctly afterward
- CPU-scheduling information. This information includes a process priority, pointers to scheduling queues, and any other scheduling parameters
- Memory-management information. This information may include such items as the value of the base and limit registers and the page tables, or the segment tables, depending on the memory system used by the operating system
- Accounting information. This information includes the amount of CPU and real time used, time limits, account numbers, job or process numbers, and so on
- I/O status information. This information includes the list of I/O devices allocated to the process, a list of open files, and so on.