Process

What is a Process?

Basically, a process is a simple program.

A process is actively running software or a computer code. Any procedure must be carried out in a precise order. An entity that helps in describing the fundamental work unit that must be implemented in any system is referred to as a process.

In other words, we create computer programs as text files that, when executed, create processes that carry out all of the tasks listed in the program.

When a program is loaded into memory, it may be divided into the four components stack, heap, text, and data to form a process. The simplified depiction of a process in the main memory is shown in the diagram below.

Process

Consists of three components

  • An executable program
  • Associated data needed by the program
  • Execution context of the program
    • All information the operating system needs to manage the process
  • So what are the process elements in detail? Thus we can say that a process consists of program code and associated data plus a Process Control Block.

For a single-processor computer, at any given time, at most one process is executing and that process is in the running state.

Trace: behaviour of an individual process by listing the sequence of instructions that execute for that process. We can characterize behaviour of the processor by showing how the traces of the various processes are interleaved.

Process Elements

  • Identifier
    • Usually abbreviated as PID (process identifier)
    • A unique identifier associated with this process, to distinguish it from all other processes
  • State
    • If the process is currently executing, it is in the running state
    • E.g., suspended, waiting, running
  • Priority
    • Relative to other processes
  • Program counter
    • The address of the next instruction in the program to be executed
  • Memory pointers
    • Pointers + shared memory blocks
  • Context data
    • Registers, PSW, program counter
  • I/O status information
    • Outstanding I/O requests, used I/O devices
  • Accounting information
    • Amount of processor time, time limits, threads
    • Try out ‘top’, ‘ulimit’

The information in this list is stored in a data structure called Process Control Block that is created and managed by the OS.

Process States

Creation and Termination

What is a Core Dump?

We introduce the Five-State Model to be more efficient. Therefore now we have:

Using two queues:

Process Switching

When to switch processes: First, let us consider system interrupts. Actually, we can distinguish, as many systems do, two kinds of system interrupts, one of which is simply referred to as an interrupt, and the other as a trap.

The former is due to some sort of event that is external to and independent of the currently running process, such as the completion of an I/O operation.

Trap: Relates to an error or exception condition generated within the currently running process, such as an illegal file access attempt.

With an ordinary interrupt, control is first transferred to an interrupt handler, which does some basic housekeeping and then branches to an OS routine that is concerned with the particular type of interrupt that has occurred.

Examples:

  • Clock interrupt
  • I/O interrupt
  • Memory fault

With a trap, the OS determines if the error or exception condition is fatal. If it is, then the currently running process is moved to Exit state and a process switch occurs. If it is not fatal, then the action of the OS will depend on the error and the design of the OS. It may attempt some recovery procedure or simply notify the user. It can do a process switch or resume the currently running process.

Mode Switching We include the Interrupt stage as part of the instruction cycle. In the interrupt stage, the processor checks to see if any interrupts are pending, indicated by the presence of an interrupt signal. If noone are pending, processor proceeds to the fetch stage and fetches the next instruction of the current program in the current process. If an interrupt is pending, processor does:

  1. Sets the program counter to the starting address of an interrupt handler program
  2. Witches from user mode to kernel mode so that the interrupt processing code may include privileged instructions

Change of Process State

Concepts about Processes

  • Resource ownership
  • Scheduling/execution

Process Attributes

Interaction Among Processes

  1. Processes unaware of each other
  2. Processes indirectly aware of each other
  3. Process directly aware of each other