A question that arises in discussing operating systems involves what to call all the CPU activities. A batch system executes jobs, whereas a time-shared system has user programs or tasks. Even on a single-user system, a user may be able to run several programs at one time: a word processor, a Web browser, and an e-mail package. And even if a user can execute only one program at a time, such as on an embedded device that does not support multitasking, the operating system may need to support its own internal programmed activities, such as memory management. In many respects, all these activities are similar, so we call all of them processes.

The terms job and process are used almost interchangeably in this text. Although we personally prefer the term process, much of operating-system theory and terminology was developed during a time when the primary activity of operating systems was job processing. It would be misleading to avoid using commonly accepted terms that include the word job (such as job scheduling) simply because the process has superseded the job.

What is a process?

A process is a program in execution. 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 a memory
that is dynamically allocated during process run time. The components of a process are the program to be executed, the data on which the program will execute, the resources required by the program such as memory and file(s) – and the status of the execution. CPU registers (general purpose, floating­point)

Is a process the same as a program? No!, it is both more and less.

  • More: A program is just part of a process context. tar can be executed by two different people same program (shared code) as part of different processes.
  • Less: A program may invoke several processes. cc invokes cpp, cc1, cc2, as, and ld.

Execution model

Over years, operating system designers evolved a model that makes concurrency easier to deal with. In this model, each runnable software on the computer often a component of the operating system itself is organized into a number of (sequential) processes, each viewed as a block of code with a pointer showing the next instruction to be executed.
How can several processes share one CPU?

The operating system takes care of this by making sure:
  • Each process gets a chance to run—fair scheduling.
  • They do not modify each other’s state—protection.

Process states

As a process executes, it changes state. The state of a process is defined in part by the current activity of that process. The states of a process include:

  • New: A process being created but not yet included in the pool of executable processes (resource acquisition).
  • Ready: Processes that are prepared to execute when given the opportunity.
  • Active: The process that is currently being executed by the CPU.
  • Blocked: A process that cannot execute until some event occurs.
  • Stopped: A special case of the block where the process is suspended by the operator or the user.
  • Exiting: A process that is about to be removed from the pool of executable processes (resource release).

Process Control Block

Each process is represented in the operating system by a process control block (PCB) also called a task 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

Process scheduling

The objective of multiprogramming is to have some user process running at all times. The OS keeps the CPU busy with productive work by dynamically selecting (scheduling) the next user process to become active. The (re­)scheduling is performed by a module, called the dispatcher. A dispatcher usually only executes the following primitive pseudo­code:

loop forever {
     run the process for a while.
     stop process and save its state.
     load state of another process.
}

Dispatcher at work

Process creation mechanisms

Who creates the processes and how they are supported? Every operating system has a mechanism to create processes. For example, in UNIX, the fork() system call is used to create processes. fork() creates an identical copy of the calling process. After the fork(), the parent continues running concurrently with its child competing equally for the CPU.

On the other hand, in MS­DOS, the LOAD_AND_EXEC system call creates a child process. This call suspends the parent until the child has finished execution, so the parent and child do not run concurrently.

Process termination

A process enters the exiting state for one of the following reasons:

  • Normal completion: A process executes a system call for termination (e.g., in UNIX exit() is called).
  • Abnormal termination:
    • Programming errors
    • run time
    • I/O
    • User intervention

Leave a Reply