Earlier there used to be only single-task performing systems. In this way, there used to be only one process running at a time. And it had the freedom to utilise all the resources in the system. But today, we have multitasking and multiprocessing operating systems, where more than one process runs at a time.
This creates problems such as deadlock and multiple processes requesting for the same resource, processor, or RAM space allocation to execute.
All these problems require a proper solution, and this instigates the operating system to carry out processor management.
In this article, we will discuss about introduction to process management in OS. So let us learn more about the process and its management, processor management, how they are being carried out by the operating system, and what are their different stages.
What is a process?
A process is an active execution unit of a program that performs some action. An operating system has the right to create, schedule, and terminate a process. There are four sections in a process:-
- Text: holds the current activities represented by the value of Program Counter
- Stack: holds temporary data such as local variables, functional parameters, return addresses, etc.
- Data: holds the global variables
- Heap: dynamically allocated memory to process during runtime.
The operating system controls a process by a block called Process Control Block (PCB). It is a type of Data Structure that is maintained by the OS for storing the context of each process.
What is Process Management?
Now that we know about a process and its various states and parts, let us learn about its management.
Process management involves tasks related to processing like creation, scheduling, termination, deadlock, etc. The operating systems allocate resources that allow the process to exchange information. It synchronizes among processes and safeguards the resources of other processes.
The operating system manages the running processes in the system and performs tasks like scheduling and resource allocation.
Let us see the attributes of a process at a glance.
- Process Id: a unique identifier assigned by the operating system to each process.
- Process State: there are a few possible states a process goes through during execution.
- CPU registers: stores the details of the process when it is swapped in and out of the CPU, just like the program counter.
- I/O status information: shows information like the device to which a process is allotted and details of open files.
- CPU scheduling information: processes are scheduled and executed based on priority.
- Accounting & Business information: information about the amount of CPU used and time utilities like a job or process number, real-time utilised, etc.
- Memory management information: information about the value of base registers and limit registers, segment tables, and pages.
These are the states in which a process might go during its execution. Let us know more about them-:
- New: a new process is created when a certain program is called up from secondary memory and loaded to RAM.
- Ready: a process is said to be in a ready state if it is already loaded in the primary memory/RAM for its execution.
- Running: here, the process is already executing.
- Paused (Waiting): at this stage, the process is believed to be waiting for CPU or resource allocation.
- Blocked: at this stage, the process is waiting for some I/O operation to get completed.
- Terminated: this specifies the time at which the process gets terminated by the OS.
- Suspended: this state shows that the process is ready but it has not been placed in the ready queue for execution.
Characteristics of a Process
A process has the following characteristics:-
- Process State: A process can be in several states, some of them are ready, suspend wait, and running.
- Process Control Block: The PCB is a data structure that contains information related to a process. These blocks are stored in the process table.
- Resources: Processes request various types of resources such as files, input/output devices, and network connections. The OS manages the allocation of these resources.
- Priority: Each process has a scheduling priority. Higher-priority processes are given preferential treatment and they receive more CPU time compared to lower-priority processes.
- Execution Context: Each process has its own execution context, which includes the address of the next instruction to be executed, stack pointer, and register values.
When Does Context Switching Happen?
Context switching in an operating system occurs when the system transitions from executing one process or thread to another. The context switching happens for various reasons:
- Time Slicing: In a multitasking environment, the operating system allocates a fixed time slice or quantum to each process. When a process's time slice expires, a context switch occurs to give CPU time to another process
- Interrupt Handling: When an interrupt, such as a hardware interrupt, such as keyboard input, or a software interrupt, such as a system call, occurs, the CPU must switch context to handle the interrupt's request. After handling the interrupt, the CPU returns to the original process
- Process State Changes: When a process transitions between states (e.g., from running to waiting for I/O or from waiting to ready), a context switch is necessary to manage these state changes
- Blocking Operations: When a process initiates a blocking I/O operation (e.g., reading from disk), it may be switched out, allowing other processes to execute while waiting for the I/O operation to complete
Click here to know about: What is bios
Scheduling algorithms in the context of operating systems are crucial mechanisms responsible for determining the order in which processes or threads are allocated CPU time. These algorithms are essential for efficient CPU utilization and ensuring that multiple tasks can run concurrently on a single processor.
The primary goal of scheduling algorithms is to strike a balance between optimizing system performance metrics such as throughput, response time, and fairness among processes. There are several scheduling algorithms used in operating systems. Here's a list of some of the most commonly known scheduling algorithms:
- First-Come, First-Served (FCFS)
- Shortest Job Next (SJN) or Shortest Job First (SJF)
- Round Robin (RR)
- Priority Scheduling
- Multilevel Queue Scheduling
- Priority Inversion
Advantages of Process Management
The following are some advantages of process management:-
- Concurrent Execution: Process management enables concurrent execution of multiple processes. This allows users to run multiple applications at the same time.
- Process Isolation: Process management ensures process isolation, which means different processes cannot interfere with the execution of each other.
- Resource Utilization: Resources are allocated fairly and effectively among processes to minimize starvation among lower-priority processes and maximize CPU throughput.
- Efficient Context Switching: It is the process of saving and restoring the execution of processes, efficiently performing context switching minimizes its overhead while improving the responsiveness of the OS.
Disadvantages of Process Management
The following are some advantages of process management:-
- Overhead: Process management introduces overhead for the system resources as the OS needs to maintain various complex data structures and scheduling queues. These processes require CPU cycles and memory which impacts the performance of the system.
- Complexity: Implementing complicated scheduling algorithms for managing process queues along with resource allocation makes maintaining and designing operating systems complex.
- Deadlocks: For process synchronization, various mechanisms are implemented by the OS, such as semaphores and mutex locks, however, they introduce deadlocks to the system.
- Increased Context Switching: In multitasking systems, processes switch between ready and running states many times during their execution. The process of storing the context of the process impacts system performance as it is computationally intensive.
Frequently Asked Questions
What activities does an OS perform for process management?
An operating system deals with process creation, process scheduling, resource management, device allocation, context switching, and process synchronization. The OS ensures system resources are used efficiently and high throughput is maintained.
What is the need for process management in OS?
Process management is needed for achieving fair resource allocation among processes along with multitasking. Multitasking is achieved by using various scheduling algorithms that allow processes to share CPU, the OS manages the allocation of CPU time to minimize process starvation.
What happens when a process terminates?
The operating system performs cleanup tasks when a process terminates. It notifies the caller process if applicable and it removes the process from the process table and deallocates resources. These steps ensure that system resources are released and they are available for other processes to use.
In this article, we have discussed about introduction to process management in OS. Since operating systems are one of the most popular topics among the interviewers, students generally have a weak hand when coming to OS. So if you are preparing for any company’s interview, then Coding Ninjas’ short-term course on Operating Systems will benefit you.
It is a two-month course, and here, you will be taught the core concepts of the operating systems that will help you ace the interviews. And this is not enough, you will be working on 150+ practice problems of operating systems that have been previously asked during the interviews of some tech giants.
You may also find the below-mentioned links useful if you are looking for some exclusive content on operating systems-:
- Register in Computer
- Open Source Operating System
- Disk Management in OS
- Single User Operating System
- Android Operating System
- Demand Paging in OS
This was all you needed to quench your thirst to know about Processor Management. Hope this helps you out in preparing for tech giants. You can also consider our Operating System Course to give your career an edge over others.