A process in operating system is a program that is currently in the execution phase. The operating system maintains a table that has an entry of each process in the system. This entry has information about the particular process.
In this context, we will discuss the operating system’s process. Along with process types, its life cycle, its states and the associated threads.
Content: Process in Operating System
- What is a Process?
- Process State
- Types of Processes
- Process Life Cycle
- Process Control Block
- Threads
What is a Process?
We refer to each CPU activity as a process. Although you might have come across many definitions such as:
- The process is a program (set of instructions) in execution.
- An instance of a program in execution.
- An entity that is executed by the processor etc.
We often consider the process as a sequence of instructions i.e. program code. We refer to it as a text section. Although the process has many elements other than the text section alone.
The figure above explains the other elements of a process.
- Stack – A process stores temporary data onto the stack. Temporary data such as local variables, parameters of a function, a return address etc.
- Heap- Heap is a memory allocated to the process during execution.
- Data – The data section stores the global variable.
- Text – The text section includes the program code that has to be executed.
You might have been confused between a program and a process. Usually, the readers think that the program is itself a process which is not the case.
Program Vs Process in Operating System
A program is a set of instructions that we write on a file. And this file in its executable form is stored on the hard disk. Hence it is also referred to as a passive entity as it is not currently operated by the processor.
A program becomes a process when it is being operated by the processor. That is a program becomes a process when its executable file is loaded into the main memory. We can do this using two ways:
- Double-clicking on the executable file of the program.
- Entering the name of the executable file on the command prompt.
Thus, we call a process an active entity. A processor has a program counter that provides the address of the next instruction to be executed next. The process also has a set of resources for that particular process.
There can be one or more processes associated with the same program. For example, consider a web browser program. A single user can invoke many windows of the same web browser program. Thus, each window is an individual process.
Process State
A process keeps on changing its states while in execution. If we classify we can categorise the states of a process into:
- New: It is the initial state of each process. At this stage, the process is being created.
- Running: When the processor is consistently executing the instructions. The process is in a running state.
- Waiting: The process might wait for an event to occur. Such as completion of an I/O, receiving a signal to proceed, etc.
- Ready: The process is ready for being assigned to the processor.
- Terminated: The process that completes its execution is in the terminated state.
Process Life Cycle
When the process starts its execution, it changes its state as many times as required. Well, the name of these state changes from one operating system to another.
When the process is created it is in a new/start state.
After creation, the process waits until the operating system assign it to the processor. Thus, the processor is in a ready state.
The process changes its state to a ready state as soon as it is created. Or sometimes the process gets interrupted. And the CPU is allotted to other processes. Then after serving the interrupt the process resides back in the ready state.
As the process starts its execution it is in a running state.
When the process needs to access any other resource of the system. Such as I/O devices, user input, access to a file etc. Then the process is in its waiting state.
Once the process completes its execution. The processor terminates the process and removes it from the main memory.
Types of Processes
We can classify a process into two categories depending on how much time they spend on doing I/O or computation:
- I/O bound Processes
- CPU Bound Processes
I/O bound Processes
The I/O bound processes spend most of their time in performing the I/O operations.
CPU Bound Processes
The CPU bound processes spend more of their time performing the computations.
If a processor has all the processes as I/O bound processes then the ready queue will always be empty. As there are processes waiting to utilize the CPU. Hence the short-term scheduler does not have any work to do.
If a processor has all the processes as CPU bound processes then the I/O waiting queue will always be empty. As all the processes will be there in the ready queue waiting for execution.
Thus, the process must have a perfect mix of I/O bound processes and CPU bound processes. So that the system remains balanced.
Depending upon the nature of the process it can be divided into two categories:
- Independent Process
- Cooperating Process
Independent Process
This process does not put any impact on the other process. Nor does it get impacted by some other processes in the system. This is because the process does not share any data with any other process.
Cooperating Process
This process can put an impact on the other processes of the system. Or it can get impacted by some other processes in the system. This is because the cooperating processes share data with the other processes.
Process Control Block (PCB)
The operating system maintains a data structure that we refer to as a process table. This process table has one entry per process. We refer to this entry as a process control block (PCB).
The process control block consists of some important information about the specific process. We also call it a task control block. The information is about:
- Process State
The process can be in one of the states that we have discussed above. At a time, a process can only be in one state. That means the process can be new, ready, running, waiting or in a halted state. - Program Counter
It indicates the address of the next instruction that the processor has to execute next in the process. - CPU Register
The information in the program counter alone is not enough to resume after serving an interrupt. Thus, we need CPU registers to hold the information. The processor uses this information along with the program counter to resume its execution.
The number and type of CPU registers vary from one operating system to other. The most generic registers are:- Accumulators
- General-purpose registers
- Index registers
- Stack pointers, etc.
- CPU Scheduling Information
This information specifies the priority of the process. It also specifies the pointer pointing to the scheduling queues. - Memory-management Information
This information specifies the value of base and limit registers. It also includes information about the page table. - Accounting Information
This information specifies the number of resources used by the system. Such as CPU time of a process, time limits and process numbers. - I/O Status
This information specifies the list of I/O devices that are allocated to a process for its execution.
Thus, the information contained by each PCB varies from process to process.
Threads
A process has its own address space and has a single thread of control. However, a process in its address space can have multiple threads of control. To understand it better let us take an example:
If you run a word-processor program, you are running a process with a single thread of control. So, at a time you can perform only one task on the word processor. Either you can type characters or perform spellcheck or perform word count etc.
But the modern operating system allows a process to have multiple threads. That allows a process to perform multiple tasks at the same time. As a process can have multiple threads, information of each thread is included in the PCB of that process.
So, this is all about the process in the operating system. We have discussed how it differs from the program. Further, we have discussed the process control block that maintains the information about a particular process.
We have learnt about the different states that a process passes through in its lifecycle. And at last, we have discussed types of processes in the operating system.
Leave a Reply