Program vs Process
A process is a program in execution. For example, when we write a program in C or C++ and compile it, compiler creates a binary code. The original code and Binary code, both are programs. When we actually run the binary code, it becomes a process.

A process is an ‘active’ entity as oppose to program which considered to be a ‘passive’ entity. A single program can create many processes when run multiple times, for example when we open an exe or binary file multiple times, many instances begin (many processes are created).

How Does a process looks in Memory?

Process | (Introduction and different states)

[ad type=”banner”]

Text Section: Process is also sometime known as the Text Section.It also includes the current activity represented by the value of Program Counter.
Stack: Stack contains the temporary data such as function parameters, return address and local variables.
Data Section: Contains the global variable.
Heap Section: Dynamically allocated memory to process during its run time.
Refer this for more details of sections.

 

Attributes or Characteristics of a Process
A process has following Attributes.

1. Process Id:    A unique identifier assigned by operating system
2. Process State: Can be ready, running, .. etc
3. CPU registers: Like Program Counter (CPU registers must be saved and 
                  restored when a process is swapped out and in of CPU)
5. Accounts information:
6. I/O status information: For example devices allocated to process, 
                           open files, etc
8. CPU scheduling information: For example Priority (Different processes 
                               may have different priorities, for example
                               a short process may be assigned low priority
                               in shortest job first scheduling)

[ad type=”banner”]

All the above attributes of a process are also known as Context of the process.
Every Process has its known Program control Block(PCB) i.e each process will have a unique PCB. All the Above Attributes are the part of the PCB.

 

States of Process:
A process is in one of the following states

1. New: Newly Created Process (or) being created process.

2. Ready: After creation Process moves to Ready state, i.e., 
          process is ready for execution.

3. Run: Currently running process in CPU (only one process at
        a time can be under execution in a single processor).

4. Wait (or Block): When process request for I/O request.

5. Complete (or Terminated): Process Completed its execution.

6. Suspended Ready: When ready queue becomes full, some processes 
                    are moved to suspend ready state

7. Suspended Block: When waiting queue becomes full.
[ad type=”banner”]Process | (Introduction and different states)

[ad type=”banner”]

Context Switching
Process of saving the context of one process and loading the context of other process is known as Context Switching. In simple term it is like loading and unloading of process from running state to ready state.

When does Context switching happen?
1. When a high priority process comes to ready state, compared to priority of running process
2. Interrupt Occurs
3. User and Kernel mode switch: (It is not necessary though)
4. Preemptive CPU scheduling used.

Context Switch vs Mode Switch
A mode switch occurs when CPU privilege level is changed, for example when a system call is made or a fault occurs. The kernel works in more privileged mode than a standard user task. If a user process wants to access things which are only accessible to kernel, a mode switch must occur. The currently executing process need not to be changed during a mode switch.
A mode switch typically occurs for a process context switch to occur. Only the Kernel can cause a context switch.

CPU Bound vs I/O Bound Processes:
A CPU Bound Process requires more amount of CPU time or spends more time in the running state.
I/O Bound Process requires more amount of I/O time and less CPU time. I/O Bound process more time in the waiting state.

[ad type=”banner”]