top of page
shubhangisingh453

Understanding Process Management in Operating Systems



📙 Introduction


A process is a program in execution. When we execute a program, it becomes a process. In an operating system, the process is the fundamental unit of execution. In this tutorial, we will discuss the various aspects of processes in operating systems.


📙 Process Subtypes


There are two types of processes in an operating system:


✔ User Process

A user process is a process that is created and controlled by the user. It runs in the user space and has limited access to system resources.


✔ System Process

A system process is a process that is created and controlled by the operating system. It runs in the kernel space and has access to all system resources.


📙 Example of Processes


Let's take a web browser as an example. When we open a web browser, it becomes a process. It creates multiple child processes for each tab, extension, and plugin. Each child process is independent of the other and has its own memory space.


📙 Components of a Process Control Block (PCB)


A process control block (PCB) is a data structure used by operating systems to store information about a process. The PCB is created by the operating system when a process is created and is used to manage and track the progress of the process. In this section, we will explain the components of a PCB in detail with examples.

The following are the components of a PCB:

  1. Process ID (PID)

  2. Program Counter (PC)

  3. CPU Registers

  4. Process State

  5. Memory Limits

  6. Open Files

  7. CPU Scheduling Information

Let's discuss each component in detail:


✔ Process ID (PID)


A process ID (PID) is a unique identifier assigned by the operating system to each process. The PID is used by the operating system to track the progress of the process and to manage system resources such as memory, CPU time, and I/O operations. The PID is an integer value and is usually assigned sequentially, starting from 1.

For example, let's say we have three processes running on a system. The PIDs assigned to these processes could be 1, 2, and 3.


✔ Program Counter (PC)


The program counter (PC) is a register in the CPU that contains the address of the next instruction to be executed. The PC is used by the operating system to keep track of the progress of the process and to resume execution of the process after it has been suspended.

For example, let's say we have a process running a program that contains ten instructions. The PC for this process would initially be set to the address of the first instruction. As the process executes instructions, the PC would be updated to point to the next instruction to be executed.


✔ CPU Registers


CPU registers are small, high-speed storage locations within the CPU that hold data and instructions that the CPU is currently processing. The CPU registers are used by the operating system to save and restore the state of the process when it is suspended and resumed.

For example, let's say we have a process that is using the accumulator register to perform a calculation. The operating system would save the value of the accumulator in the process's PCB when the process is suspended and restore the value when the process is resumed.


✔ Process State


The process state indicates the current status of the process. The process state can be one of the following:

  • Running: The process is currently running on the CPU.

  • Ready: The process is waiting to be assigned to a CPU.

  • Blocked: The process is waiting for an event, such as I/O, to complete.

The process state is used by the operating system to schedule the execution of the process and to manage system resources.

For example, let's say we have a process that is waiting for data to be read from a file. The process state for this process would be set to Blocked, indicating that the process is waiting for the I/O operation to complete.


✔ Memory Limits


Memory limits define the range of memory addresses that the process can access. The memory limits are used by the operating system to ensure that the process does not access memory outside of its allocated memory range.

For example, let's say we have a process that has been allocated 1GB of memory. The memory limits for this process would be set to the start and end addresses of the allocated memory range.


✔ Open Files


Open files are files that the process has opened for reading or writing. The open files are used by the operating system to keep track of the files that the process has opened and to ensure that the process does not access files that it does not have permission to access.

For example, let's say we have a process that has opened a file called "myfile.txt" for writing. The open files component of the process's PCB would contain information about the opened file, such as the file name, file descriptor, and file mode.


✔ CPU Scheduling Information


The CPU scheduling information component contains information about the process's priority, scheduling algorithm, and other scheduling-related information. The CPU scheduling information is used by the operating system to determine which process should be assigned to the CPU next.

For example, let's say we have two processes with different priorities running on a system. The process with the higher priority would be assigned to the CPU first, based on the CPU scheduling information in the process's PCB.


📙 Process in the Memory


A process in an operating system comprises of several components in memory that are used by the operating system to execute the process. In this section, we will discuss these components in detail with examples.

The following are the components of a process in memory:

  1. Text Segment (Code Segment)

  2. Data Segment

  3. Stack Segment

  4. Heap Segment

Let's discuss each component in detail:


✔ Text Segment (Code Segment)


The text segment, also known as the code segment, contains the executable instructions of the process. The instructions in the text segment are typically read-only, and the operating system maps this segment into the process's virtual address space.

For example, let's say we have a process that contains a program that calculates the factorial of a number. The instructions for this program would be stored in the text segment.


✔ Data Segment


The data segment contains data that is initialized when the process is created, such as global variables and static data. The data segment is typically read-write, and the operating system maps this segment into the process's virtual address space.

For example, let's say we have a process that contains a program that calculates the factorial of a number. The initial value of the variable "n" would be stored in the data segment.


✔ Stack Segment


The stack segment is used to store information related to function calls, such as local variables and function parameters. The stack segment grows downward, and the operating system maps this segment into the process's virtual address space.

For example, let's say we have a process that contains a program that calculates the factorial of a number. The value of the variable "n" would be stored on the stack when the function to calculate the factorial is called.


✔ Heap Segment


The heap segment is used for dynamic memory allocation, such as when the process uses the "malloc" function in C. The heap segment grows upward, and the operating system maps this segment into the process's virtual address space.

For example, let's say we have a process that contains a program that reads data from a file and stores it in memory. The process would use the heap segment to dynamically allocate memory to store the data read from the file.


📙 How Do Multiple Processes Share RAM?


There are two models for how multiple processes can share RAM:


✔ Single Contiguous Model


In the single contiguous model, all processes are allocated a contiguous block of memory. Each process has its own memory space, but the memory is physically contiguous. This model is used in traditional Unix systems.


✔ Partition Model


In the partition model, the memory is divided into fixed-size partitions. Each partition can be allocated to a process, and multiple processes can share the same partition. This model is used in modern operating systems such as Windows and Linux.


📙 Kernel Space and User Space


In an operating system, the kernel is the central component that manages system resources and provides services to user programs. The kernel space is the memory space reserved for the kernel, and the user space is the memory space reserved for user programs.

User programs cannot access the kernel space directly. They have to use system calls to request services from the kernel. This is done to prevent user programs from accessing and modifying the kernel's memory, which could cause system instability and security issues.


📙 Kernel and Multiple Processes


In an operating system, the kernel is responsible for managing multiple processes. The kernel schedules the processes, allocates memory to them, and provides services to them.

Each process has its own memory space and cannot access the memory space of other processes directly. The kernel provides mechanisms for inter-process communication (IPC) to allow processes to communicate with each other and share data.

The kernel also provides protection mechanisms to ensure that one process cannot access or modify the memory space of another process without permission. This is done through the use of memory protection mechanisms such as virtual memory and memory mapping.


📙 Deadlock Prevention


Deadlock prevention is a technique used in operating systems to avoid situations where two or more processes are blocked, waiting for each other to release resources, and unable to proceed. In this tutorial, we will discuss various techniques used for deadlock prevention in detail.


✔ Mutual Exclusion


Mutual exclusion is a technique used to prevent multiple processes from accessing the same resource simultaneously. This technique ensures that a resource can be accessed by only one process at a time, avoiding any conflicts that might lead to a deadlock.

For example, let's consider a shared printer. If two processes try to access the printer simultaneously, a conflict may arise, leading to a deadlock. Mutual exclusion ensures that only one process can access the printer at a time, avoiding any conflicts.


✔ Hold and Wait


The hold and wait technique is used to prevent a process from holding onto a resource while waiting for another resource. This technique requires a process to obtain all the resources it needs before starting execution, eliminating the possibility of a deadlock.

For example, if a process needs two resources, it must acquire both resources before starting execution. This technique ensures that a process does not hold a resource while waiting for another resource, preventing any possibility of a deadlock.


✔ No Preemption


The no-preemption technique is used to prevent a process from being interrupted and having its resources forcefully taken away. This technique ensures that a process completes its execution and releases its resources voluntarily, avoiding any conflicts that might lead to a deadlock.

For example, if a process is using a resource, it cannot be preempted and forced to release the resource. The process must complete its execution and release the resource voluntarily.


✔ Circular Wait


The circular wait technique is used to prevent processes from waiting for resources in a circular chain. This technique ensures that a process waits for a resource only if the resource is not currently being held by another process.

For example, if process A is waiting for a resource held by process B, process B must release the resource before process A can acquire it. This technique ensures that processes do not wait for resources in a circular chain, avoiding any possibility of a deadlock.


In this tutorial, we have discussed the various aspects of processes in operating systems. We have covered the different types of processes, components of a PCB, what a process comprises of in the memory, how multiple processes can share RAM, and the concept of kernel space and user space.


Thanks for reading, and happy coding!


Understanding Process Management in Operating Systems -> Synchronization in Operating Systems: Techniques and Examples

bottom of page