This topic comes under CPU Scheduling. During the whole course of operating system you will hear this term 'process' so understanding about process is very important. SO,let's get started, shall we?
Process
The basic definition of a process is that it is a program in execution which executes in a sequential manner. Now, many students confuses between a process and a program so let's see some basic differences between them:
Process Program
1. A Process is a program in execution. A program is a set of instruction to be executed.
2. It is an active entity. It is a passive entity.
3. Process resides in the main memory. Program resides in the disk.
When a program is loaded into the main memory it becomes a process. A process can be sub-divided into 4 parts:
- Stack : Stack contain temporary data such as local variables, function/methods, return address.
- Heap : This part is reserved for dynamic allocation of variables during run time.
- Text : This includes values of Program counter and content of Processor's registers.
- Data : This part contain global and static variables.
A process can have 5 states as given in the picture below:
- New : When a process is being created then it is said to be in new state.
- Ready : When a enters main memory for execution it is said to be in Ready state.
- Run : When a process is being executed by CPU then it is in run state.
- Wait : When a process request for an I/O operation then it is in wait state.
- Complete/Terminated : When a process is done with its execution then it is terminated.
Note: If a process is running in the CPU and it is taking more time to execute than expected or if it is blocked then there is a clock being installed between ready and run state which ensures that a process must execute its processing in the given time else it is stopped and pushed back to the ready queue again.
Process Control Block
A process has various attributes associated with it and these attributes are managed by a data structure called Process Control Block.
These attributes of a process are:
- Process Id : Every process has an id associated with it which uniquely identifies it.
- State : It determines the current state of a process i.e new, ready, run...
- Pointer : It is a pointer which points to the parent process.
- Priority : It determines whether to allow/disallow access to system resources.
- Program Counter : It contain address of next instruction to be executed for the process.
- CPU registers : These are the registers where process need to be stored for execution.
- I/O information : It includes list of I/O devices allocated to the process.
- Accounting information: This includes amount of CPU used for program execution, time limits, execution ID etc.
- Memory management information: It includes information of page tables, memory limits etc.
- CPU scheduling information : Process priority and other scheduling information which require to schedule the process.
A CPU-bound process is a process which requires more of CPU execution than I/O operations.
An I/O-bound process is a process which requires more of I/O execution than CPU execution.
Context-Switching
It is the process of saving the state of one process and loading the saved state of another process.
In layman terms it is like loading and unloading the process from running state to ready state.