Thursday, July 16, 2009

The Concept of Process

a. 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.

Primary Process States

The following typical process states are possible on computer systems of all kinds. In most of these states, processes are "stored" on main memory.






b. Process Control Block

A Process Control Block (PCB, also called Task Control Block or Task Struct) is a data structure in the operating system kernel containing the information needed to manage a particular process. The PCB is "the manifestation of a process in an operating system".

Included information:


Implementations differ, but in general a PCB will include, directly or indirectly:

  • The identifier of the process (a process identifier, or PID)
  • Register values for the process including, notably,
    the
    Program Counter value for the process
  • The address space for the process
  • Priority (in which higher priority process gets first preference. eg., nice value on Unix operating systems)
  • Process accounting information, such as when the process was last run, how much CPU time it has accumulated, etc.
  • Pointer to the next PCB i.e. pointer to the PCB of the next process to run

  • I/O Information (i.e. I/O devices allocated to this process, list of opened files, etc)


During a context switch, the running process is stopped and another process is given a chance to run. The kernel must stop the execution of the running process, copy out the values in hardware registers to its PCB, and update the hardware registers with the values from the PCB of the new process.

c. Threads

A thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.

On a single processor, multithreading generally occurs by time-division multiplexing (as in multitasking): the processor switches between different threads. This context switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. On a multiprocessor or multi-core system, the threads or tasks will generally run at the same time, with each processor or core running a particular thread or task. Support for threads in programming languages varies: a number of languages simply do not support having more than one execution context inside the same program executing at the same time.


No comments: