- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is a process in Operating System?
A process is an active program i.e a program that is under execution. It is more than the program code as it includes the program counter, process stack, registers, program code etc. Compared to this, the program code is only the text section.
A program is not a process by itself as the program is a passive entity, such as file contents, while the process is an active entity containing program counter, resources etc.
A process changes its state as it executes. This state partially depends on the current activity of a process. The different states that a process is in during its execution are explained using the following diagram −
The following are the states −
- New - The process is in the new state when it has just been created.
- Ready - The process is waiting to be assigned the processor by the short-term scheduler.
- Running - The process instructions are being executed by the processor.
- Waiting - The process is waiting for some event such as I/O to occur.
- Terminated - The process has completed its execution.
Process Control Block
A process control block is associated with each of the processes. It contains important information about the process it is associated with. Some of this information is as follows −
The following comes under PCB −
- Process State - This specifies the process state i.e. new, ready, running, waiting or terminated.
- Process Number - This shows the number of the particular process.
- Program Counter - This contains the address of the next instruction that needs to be executed in the process.
- Registers - This specifies the registers that are used by the process. They may include accumulators, index registers, stack pointers, general purpose registers etc.
- List of open files - These are the different files that are associated with the process.
There are many scheduling queues that are used to handle processes. When the processes enter the system, they are put into the job queue. The processes that are ready to execute in the main memory are kept in the ready queue. The processes that are waiting for the I/O device are kept in the device queue.
A diagram that represents process scheduling is as follows −
The different schedulers that are used for process scheduling are −
Long Term Scheduler
The job scheduler or long-term scheduler selects processes from the storage pool and loads them into memory for execution. The job scheduler must select a careful mixture of I/O bound and CPU bound processes to yield optimum system throughput. If it selects too many CPU bound processes then the I/O devices are idle and if it selects too many I/O bound processes then the processor has nothing to do.
Short Term Scheduler
The short-term scheduler selects one of the processes from the ready queue and schedules them for execution. The short-term scheduler executes much more frequently than the long-term scheduler as a process may execute only for a few milliseconds.
Medium Term Scheduler
The medium-term scheduler swaps out a process from main memory. It can again swap in the process later from the point it stopped executing. This is helpful in reducing the degree of multiprogramming. Swapping is also useful to improve the mix of I/O bound and CPU bound processes in the memory.
Removing a process from the CPU and scheduling another process requires saving the state of the old process and loading the state of the new process. This is known as context switching. The context of a process is stored in the Process Control Block (PCB) and contains the process register information, process state, and memory information.
The dispatcher is responsible for context switching. It saves the context of the old process and gives control of the CPU to the process chosen by the short-term scheduler.
- Process Deadlocks in Operating System
- Process Communication in Operating System
- Process Creation vs Process Termination in Operating System
- What is a batch operating system?
- What is a Multiprocessing Operating System?
- What is a distributed Operating System?
- What is a multiprogramming Operating System?
- What is an Operating System?
- What is the operating system?
- What is process creation in Operating Systems?
- What is the operating system evolution?
- What is the Network Operating System?
- What is an embedded operating system?
- What is the operating system structure?
- What is Context Switching in Operating System?