Process Management in Operating Systems
Process Management in Operating Systems
i) Program vs Process:
• A program is a set of instructions (code) that is stored on the disk. It is
passive, meaning it doesn’t do anything on its own.
• A process is the running instance of a program. It is active, meaning it is
performing tasks when executed.
Difference between process and the program
S. No Process Program
1 A process is actively Program is a set of
running software or a instructions which are
computer code. Any executed when the
procedure must be certain task is allowed
carried out in a precise to complete that certain
order. An entity that task
helps in describing the
fundamental work unit
that must be
implemented in any
system is referred to as
a process
2 Process is Dynamic in Program is Static in
Nature Nature
3 Process is an Active in Program is Passive in
Nature Nature
4 Process is created Program is already
during the execution existed in the memory
and it is loaded directly and it is present in the
into the main memory secondary memory.
Program is already
existed in the memory
1
Advanced Operating System Module 2
Example:
• When you write a program in C or C++, it is saved as a file. This file is the
program.
• When you compile this program, the compiler creates an executable file
(like a .exe file). This executable file is still just a program.
• When you run the .exe file, it becomes a process because it is now being
executed by the system.
2
Advanced Operating System Module 2
Active vs Passive:
• Active Entity: A process is active, meaning it consumes CPU time,
memory, and other resources to perform its tasks.
• Passive Entity: A program is passive, meaning it is just stored data until it
is executed.
Practical Example:
• Think of a text editor like Notepad on your computer. Notepad itself is a
program stored on your hard drive.
• When you open Notepad, it becomes a process because it is now
running on your computer.
• If you open Notepad multiple times, each time you open it, a new
process is created.
3
Advanced Operating System Module 2
Deadlock Prevention:
• The OS also ensures that the processes don’t block each other (known
as deadlock), which could freeze the system.
Process Synchronization:
• The OS ensures that processes work in sync with each other, especially
when multiple processes are sharing data or resources.
System Responsiveness:
• Good process management allows multiple applications to run at the
same time, making the computer more responsive and efficient.
Example:
• When you are running a web browser, music player, and a game at the
same time, process management ensures they all run smoothly by
giving each one the right amount of system resources.
4
Advanced Operating System Module 2
• This part contains the instructions or code of the program. It tells the
computer what tasks to perform.
• It also includes the Program Counter (PC), which keeps track of which
instruction is being executed at any moment.
5
Advanced Operating System Module 2
2. Stack:
3. Data Section:
• This part holds global variables. These are variables that can be
accessed by the entire program, not just a single function.
4. Heap Section:
• The heap is used for dynamic memory allocation. This means that
memory is allocated to the process while it's running.
• For example, if the program needs more memory for a new task, it can
request more from the heap during its execution.
6
Advanced Operating System Module 2
2. Process State:
• The process can be in different states such as:
➢ Ready: The process is ready to run but waiting for the CPU.
➢ Running: The process is currently being executed by the CPU.
➢ Waiting: The process is waiting for some event to happen (like
input from the user).
3. CPU Registers:
• These are small memory locations inside the CPU. Important data
like the Program Counter (PC) is stored here.
• The PC keeps track of the next instruction to execute. When a
process is paused (swapped out), the CPU saves this information, so
it can resume the process later from the same point.
4. Accounts Information:
• This includes details like:
➢ How much CPU time the process has used.
➢ Time limits on the process.
➢ The Execution ID of the process (who started it).
5. I/O Status Information:
• Information about the input/output devices used by the process. For
example, the files the process has opened or devices (like printers) it
is using.
6. CPU Scheduling Information:
• This includes the priority of the process. For example:
➢ Some processes have higher priority, meaning they will be
executed before lower-priority processes.
➢ A shorter process might get high priority in certain scheduling
methods (like Shortest Job First scheduling).
Process Control Block (PCB):
❖ All the above information is stored in a Process Control Block (PCB).
❖ Each process has its own PCB, which contains everything the OS needs
to manage the process.
7
Advanced Operating System Module 2
v) States of a Process
When a program becomes a process (a running program), it goes through
different stages or states during its life cycle.
1. New:
• This is the starting state. When a process is created, it starts in the
New state.
• Example: When you double-click to open an application, the process
is in the “New” state while it’s being created.
2. Ready:
• After a process is created, it moves to the Ready state. This means
the process is ready to run but is waiting for the CPU to be free.
• Example: Your application is loaded and ready to run, but the CPU is
still busy with other tasks, so it is waiting for its turn.
8
Advanced Operating System Module 2
3. Running:
• The process moves to the Running state when it is currently being
executed by the CPU.
• Only one process can be in the Running state at a time on a single
processor system.
• Example: When you start typing in your text editor, the process is
actively running in the CPU.
4. Wait (or Block):
• The process enters the Wait or Blocked state when it needs to wait
for some input/output operation, like reading a file or waiting for user
input.
• Example: When you’re downloading a file, the process might enter
the Wait state until the file finishes downloading.
5. Complete (or Terminated):
• When the process finishes its task or is terminated by the system or
user, it moves to the Complete (or Terminated) state.
• Example: After you close an application, the process enters the
“Terminated” state because its execution is finished.
6. Suspended Ready:
• When the Ready Queue (the list of processes waiting to run)
becomes too full, some processes are moved to the Suspended
Ready state.
• This means they are ready to run but have been temporarily moved
out of the main memory to free up space.
• Example: If many programs are open on your computer, some might
be moved to the suspended state to free up memory for more
important processes.
9
Advanced Operating System Module 2
7. Suspended Block:
• If a process is in the Wait state (waiting for an I/O operation) but the
Wait Queue (list of waiting processes) becomes full, the process is
moved to the Suspended Block state.
• This means it is waiting for an event (like a file to be loaded) but is
suspended to free up memory space.
• Example: If multiple background tasks are waiting for user input,
some might be suspended to free up system resources.
a) Creating
10
Advanced Operating System Module 2
11
Advanced Operating System Module 2
1. Request:
• The process of creation begins with a request from a user or a system
component, such as an application or the operating system itself, to
start a new process.
2. Allocating Resources:
• The operating system allocates necessary resources for the new
process, including memory space, a unique process identifier (PID),
a process control block (PCB), and other essential data structures.
3. Loading Program Code:
• The program code and data associated with the process are loaded
into the allocated memory space.
4. Setting Up Execution Environment:
• The OS sets up the initial execution environment for the process.
5. Initialization:
• Any initializations required for the process are performed at this
stage. This might involve initializing variables, setting default values,
and preparing the process for execution.
6. Process State:
• After the necessary setup, the new process is typically in a “ready” or
“waiting” state, indicating that it is prepared for execution but hasn’t
started running yet.
b) Dispatching/Scheduling
12
Advanced Operating System Module 2
1. Process Selection:
2. Context Switching:
• Once the context switch is complete, the OS loads the saved state of
the selected process from its PCB. This includes restoring the
program counter and other CPU registers to the values they had
when the process was last preempted or voluntarily yielded to the
CPU.
4. Execution:
13
Advanced Operating System Module 2
6. Scheduling Algorithms:
14
Advanced Operating System Module 2
15
Advanced Operating System Module 2
d) Preemption
16
Advanced Operating System Module 2
17
Advanced Operating System Module 2
e) Termination of Process
18
Advanced Operating System Module 2
19
Advanced Operating System Module 2
1. Process State: The PCB stores the current state of a process, which helps
the Operating System manage and schedule it. A process can be in
different states like “running,” “waiting,” “ready,” or “terminated.”
2. Process ID: Every process gets a unique number called a Process ID when
it’s created. This ID helps the Operating System keep track of and identify
different processes.
20
Advanced Operating System Module 2
21
Advanced Operating System Module 2
22
Advanced Operating System Module 2
23
Advanced Operating System Module 2
Categories of Scheduling
Scheduling is divided into two main categories:
1. Non-Preemptive:
• In this type, a process cannot be interrupted once it starts
running. It will finish its task before the Operating System can
take its resources.
• When the process finishes, it may switch to a waiting state, at
which point resources can be reassigned.
2. Preemptive:
• Here, the Operating System gives a process resources for a set
amount of time.
• If a higher-priority process needs to run, the OS can interrupt
the current process and switch it back to a ready state. This
allows the OS to prioritize more important tasks.
24
Advanced Operating System Module 2
25
Advanced Operating System Module 2
3. Medium-Term Scheduler:
• This scheduler manages suspending and resuming processes.
• It moves processes between main memory and disk when needed,
which helps manage memory use and maintain a balance between
I/O and CPU-bound processes.
• It can reduce the number of processes running at once to keep things
efficient.
Some Other Schedulers
1. I/O Schedulers:
• These manage how I/O operations (like reading from or writing to disks)
are handled.
• They use different methods, like First-Come, First-Served (FCFS) or
Round Robin (RR), to decide the order of operations.
2. Real-Time Schedulers:
26
Advanced Operating System Module 2
• This queue contains processes that are ready to run but are waiting for
CPU time.
• When a process starts, it joins the ready queue until the CPU is free to
execute it.
• Characteristics:
➢ Uses a First-In-First-Out (FIFO) method, meaning the first process to
enter the queue is the first to get CPU time.
➢ Processes are chosen for execution based on scheduling algorithms
like First-Come, First-Served (FCFS), Shortest Job First (SJF), or
Priority Scheduling.
3. Waiting Queue
• This queue holds processes waiting for a specific event, like an I/O
operation (e.g., waiting for data from a disk).
• A process remains here until the resource it needs becomes available.
• Characteristics:
27
Advanced Operating System Module 2
• This queue has several levels, each with different priority levels.
• Processes are assigned to a specific queue based on their importance.
• For example, high-priority tasks like system updates might go into one
queue, while lower-priority tasks like background processes go into
another.
• Characteristics:
28
Advanced Operating System Module 2
x) Context Switching
29
Advanced Operating System Module 2
30
Advanced Operating System Module 2
• The Process Control Block (PCB) is like a detailed file that holds all the
information about a process. It includes details such as:
1. The process's current state (running, waiting, etc.).
2. The CPU registers (the tiny memory spots where current data is
held).
3. Memory management information.
4. Process identification.
5. When a process is created, the operating system sets up a PCB to
keep track of everything related to that process.
Steps in Context Switching
3. Select a New Process: The system looks for another process in the
waiting list that is ready to run.
4. Load the New Process State: The system retrieves the saved state of
the new process from its PCB and starts running it.
This process helps keep everything organized and allows the computer to
handle many tasks at once efficiently.
31
Advanced Operating System Module 2
32
Advanced Operating System Module 2
Advantages of IPC
1. Efficient communication: Different applications can communicate
and exchange data without interfering with each other.
2. Glitch-free data sharing: Information can be shared smoothly
between processes.
3. Simplifies maintenance and debugging: Since programs are divided
into smaller parts that work independently, it’s easier to identify and fix
errors.
4. Multitasking: Users can perform multiple tasks (like listening to
music, writing code, and editing documents) at the same time.
5. Parallel task execution: Tasks can be divided and handled by
different processors, improving speed and efficiency.
Disadvantages of IPC
1. Shared memory issues: Processes using shared memory need to
ensure they don’t write to the same memory location at the same time,
which can lead to data corruption.
2. Synchronization and protection: Shared storage models can cause
synchronization issues, which require careful management to prevent
data loss or conflicts.
3. Slower than direct function calls: Communicating through IPC is
generally slower compared to calling a function directly within the same
program.
33
Advanced Operating System Module 2
IPC Mechanisms
1. Shared Memory: Different programs access the same portion of
memory to exchange data.
2. Message Passing: Programs send messages to each other through
the operating system, which helps in communication between
processes that don’t share memory.
1. Shared Memory
34
Advanced Operating System Module 2
• The concept is that one process creates a shared memory region, and
another process can access this region to exchange data.
• Key Features:
➢ Fastest IPC method: Shared memory is the fastest way for processes
to communicate since it avoids the need for the operating system to
mediate each exchange, like in other IPC methods (e.g., message
passing).
➢ Direct communication: Processes communicate directly by reading
and writing to the shared memory space.
How it Works: Step-by-Step Explanation
Let’s walk through an example of two processes, P1 and P2, exchanging data:
Step 1: Process P1 Creates Shared Memory
35
Advanced Operating System Module 2
Example
Imagine a simple program where P1 is a sensor process that collects
temperature data and P2 is a monitor process that displays the data to users:
1. P1 (Sensor Process): Collects temperature data (e.g., 75°C) and stores it
in a shared memory region.
2. P2 (Monitor Process): Attaches to the shared memory and reads the
temperature data to display it on the screen.
The two processes continue exchanging information using the shared
memory, making the system fast and efficient.
Advantages of Shared Memory
1. Speed:
36
Advanced Operating System Module 2
2. Concurrent Access:
4. Modularity:
37
Advanced Operating System Module 2
38
Advanced Operating System Module 2
• Imagine two chat users, User1 and User2, who are chatting online. The
chat application uses message passing for communication.
• When User1 sends a message (send operation), the chat server receives
it and forwards it to User2 (receive operation).
• The communication between User1 and User2 happens without them
directly accessing each other’s devices (no shared memory).
39
Advanced Operating System Module 2
• In this scenario:
o The send message is the text User1 sends.
o The receive message is what User2 gets.
o The communication link is the connection between the two users
established by the chat server.
40
Advanced Operating System Module 2
• Imagine you have a program that downloads multiple files from the
internet.
• If you didn't use threads, the program would have to download each file
one after the other, one at a time (like a single-threaded process). This
would be slow, especially if you have many files to download.
• But with multithreading, the program can create a thread for each file
download, allowing multiple downloads to happen at the same time.
• Now, instead of waiting for one file to finish before starting another, all
files can be downloaded simultaneously.
• Each thread handles one file download independently, but all threads
share the program's resources (like the internet connection, memory,
etc.).
41
Advanced Operating System Module 2
Multithreading Models
• In some operating systems, threads can exist at both the user level and
the kernel level.
• Threads at the user level are managed by the application, while kernel-
level threads are managed by the operating system.
• By combining these two types of threads, the system can improve
performance and take advantage of multiprocessor systems.
• The three main types of multithreading models are:
1. Many-to-Many
2. Many-to-One
3. One-to-One
42
Advanced Operating System Module 2
1. Many-to-Many Model
• In this model, many user threads are mapped to many kernel threads.
This means that multiple user-level threads (the threads that are
managed by the application) are connected to kernel-level threads (the
threads that the operating system controls).
• Key Characteristics:
o Developers can create as many user threads as needed, without
worrying about the kernel-level threads.
o These user threads can run in parallel on a multiprocessor
system.
o If one user thread makes a blocking system call (like waiting for
input), the kernel can schedule another thread to run. This
ensures the entire process does not get stuck waiting.
• Example:
o Imagine a video game where multiple tasks are happening at the
same time (like rendering the game graphics, managing player
input, and controlling game logic).
o In the many-to-many model, each task can run as a separate user
thread, and the operating system can handle multiple threads at
once across different processors. This allows smooth gameplay
with multiple tasks running in parallel.
43
Advanced Operating System Module 2
[Link]-to-One Model
44
Advanced Operating System Module 2
3. One-to-One Model
45
Advanced Operating System Module 2
• This measures how much of the CPU's time is being used. Ideally, we
want the CPU to be working as much as possible, so none of its time is
wasted.
• However, on a real system, CPU usage usually ranges from 40% to 90%,
depending on how many tasks are running.
• Example:
➢ Imagine you have a factory, and you want your workers (CPU) to be
busy all the time making products (processes).
➢ If your workers are only busy 40% of the time, the factory isn’t very
efficient. But if they’re working close to 90% of the time, it means the
factory is running well.
2. Throughput
• This is the total time it takes for a process to complete, from when it’s
first submitted to when it finishes.
• This includes waiting in queues, getting processed, and finishing up.
46
Advanced Operating System Module 2
• Example:
➢ Imagine a student submits homework and the teacher takes two
days to review it.
➢ The turnaround time is two days. If another teacher reviews it in just
one day, the turnaround time is shorter.
4. Waiting Time
• This is the amount of time a process spends waiting in the ready queue
before it gets a chance to use the CPU.
• Reducing waiting time helps processes run faster.
• Example:
➢ If three students are waiting in line to ask a question and each has to
wait 30 minutes, their waiting time is 30 minutes.
➢ If we can reduce the waiting time to 10 minutes, students get their
questions answered faster.
5. Load Average
• This shows how many processes are waiting in the ready queue over a
period of time.
• Load average can be measured in 1-minute, 5-minute, and 15-minute
intervals.
• Example:
➢ If there are always 10 people waiting in line to ask a question, the
load average is high.
➢ But if only 2 people are waiting, the load average is lower, meaning
the system is less busy.
6. Response Time
• This is how long it takes from the moment a user submits a request (like
typing a command) to when the system starts responding.
• This is especially important for interactive systems where users expect
quick feedback.
47
Advanced Operating System Module 2
• Example:
➢ When you press a button on your phone and the app opens
immediately, the response time is short.
➢ If you press the button and have to wait several seconds, the
response time is long.
Scheduling Algorithms
There are various algorithms which are used by the Operating System to
schedule the processes on the processor in an efficient way.
48
Advanced Operating System Module 2
o Arrival time (AT) – Arrival time is the time at which the process
arrives in ready queue.
o Burst time (BT) or CPU time of the process – Burst time is the unit
of time in which a particular process completes its execution.
o Completion time (CT) – Completion time is the time at which the
process has been terminated.
o Turn-around time (TAT) – The total time from arrival time to
completion time is known as turn-around time. TAT can be written
as,
Turn-around time (TAT) = Completion time (CT) – Arrival time (AT) or,
TAT = Burst time (BT) + Waiting time (WT)
o Waiting time (WT) – Waiting time is the time at which the process
waits for its allocation while the previous process is in the CPU for
execution. WT is written as,
o Response time (RT) – Response time is the time at which CPU has
been allocated to a particular process first time.
▪ In case of non-preemptive scheduling, generally Waiting
time and Response time is same.
o Gantt chart – Gantt chart is a visualization which helps to
scheduling and managing particular tasks in a project. It is used
while solving scheduling problems, for a concept of how the
processes are being allocated in different algorithms.
49
Advanced Operating System Module 2
50
Advanced Operating System Module 2
3. Non-preemptive: Once a task starts, it holds the CPU until it’s done.
Even if an urgent task arrives, it cannot interrupt the current task,
leading to potential delays.
[Link] Job First (or SJF) CPU Scheduling
The Shortest Job First (SJF) is a CPU scheduling algorithm that selects the
process with the shortest burst time (execution time) to run next. This method
reduces the waiting time for processes and improves the overall efficiency of
the system.
Characteristics of SJF Scheduling:
Shortest Job first has the advantage of having a minimum average waiting time
among all scheduling algorithms.
It is a Greedy Algorithm.
It may cause starvation if shorter processes keep coming. This problem can
be solved using the concept of ageing.
51
Advanced Operating System Module 2
It is practically infeasible as Operating System may not know burst times and
therefore may not sort them.
While it is not possible to predict execution time, several methods can be
used to estimate the execution time for a job, such as a weighted average of
previous execution times.
SJF can be used in specialized environments where accurate estimates of
running time are available.
Algorithm:
• Sort all the processes according to the arrival time.
• Then select that process that has minimum arrival time and
minimum Burst time.
• After completion of the process make a pool of processes that
arrives afterward till the completion of the previous process and
select that process among the pool which is having minimum Burst
time.
How to compute below times in SJF using a program?
• Completion Time: Time at which process completes its execution.
• Turn Around Time: Time Difference between completion time and
arrival time.
Turn Around Time = Completion Time – Arrival Time
• Waiting Time(W.T): Time Difference between turn around time and
burst time.
Waiting Time = Turn Around Time – Burst Time
52
Advanced Operating System Module 2
Example-1: Consider the following table of arrival time and burst time for
five processes P1, P2, P3, P4 and P5.
The Shortest Job First CPU Scheduling Algorithm will work on the basis of
steps as mentioned below:
At time = 0,
At time= 1,
• Process P3 arrives.
• But, as P4 still needs 2 execution units to complete.
• Thus, P3 will wait till P4 gets executed.
53
Advanced Operating System Module 2
At time =2,
• Process P1 arrives and is added to the waiting table
• P4 will continue its execution.
At time = 3,
54
Advanced Operating System Module 2
At time = 4,
At time = 5,
• Process P2 arrives and is added to the waiting Table.
• P1 will continue execution.
55
Advanced Operating System Module 2
At time = 6,
At time=9,
• Process P2 is executing and P3 and P5 are in the waiting Table.
56
Advanced Operating System Module 2
At time = 11,
At time = 15,
57
Advanced Operating System Module 2
At time = 23,
Now, let’s calculate the average waiting time for above example:
• P4 = 0 – 0 = 0
• P1 = 3 – 2 = 1
• P2 = 9 – 5 = 4
• P5 = 11 – 4 = 7
• P3 = 15 – 1 = 14
• Average Waiting Time = 0 + 1 + 4 + 7 + 14/5 = 26/5 = 5.2
58
Advanced Operating System Module 2
Advantages of SJF:
Disadvantages of SJF:
59
Advanced Operating System Module 2
Step 1: At time 0, P1 arrives and starts executing since it’s the only process.
Step 2: At time 1, P2 arrives with a higher priority. If preemptive priority
scheduling is used, P1 is preempted, and P2 starts executing.
Step 3: P2 finishes at time 4. Now, the CPU selects P1 (since its priority is
higher than P3).
Step 4: P1 finishes at time 6, and then P3 starts executing.
Advantages of Priority Scheduling
60
Advanced Operating System Module 2
• Time Quantum:
o A fixed time period is determined (e.g., 100 milliseconds). This is how long
each process can use the CPU before it must yield to another process.
• Queue System:
o Processes are placed in a ready queue in the order they arrive. Each process
waits for its turn based on this order.
• Execution Cycle:
o The CPU picks the first process in the queue and gives it the CPU for the
duration of the time quantum.
o If the process finishes before the time quantum ends, it is removed from the
queue.
o If the process does not finish, it is moved to the end of the queue, and the
CPU moves on to the next process.
• Repeat:
o This cycle continues until all processes are completed.
1. Fairness: Each process gets an equal share of the CPU, making it fair
for all processes.
2. Preemptive: The scheduler can interrupt a process that has not
finished executing when its time quantum expires.
3. Easy to Implement: The algorithm is straightforward, making it easy to
implement in various systems.
61
Advanced Operating System Module 2
62
Advanced Operating System Module 2
2. Priorities Assigned:
3. Preemption:
4. Scheduling Algorithms:
63
Advanced Operating System Module 2
5. Feedback Mechanism:
64
Advanced Operating System Module 2
[Link] Allocation:
Ensures that different types of processes receive appropriate CPU
time.
[Link] Algorithms:
Different algorithms can be tailored for each queue to meet
specific process needs.
[Link]:
Important processes are executed on time due to assigned
priorities.
[Link]:
Higher-priority processes can interrupt lower-priority ones,
ensuring critical tasks are handled swiftly.
Disadvantages of MLQ CPU Scheduling:
[Link] Starvation:
65
Advanced Operating System Module 2
66
Advanced Operating System Module 2
5. Preemption:
67
Advanced Operating System Module 2
[Link]:
The scheduling algorithm can be tailored to specific system
requirements, allowing different strategies for different types of
processes.
Disadvantages of MLFQ Scheduling
[Link]:
Implementing MLFQ scheduling can be complex due to the need for
multiple queues and dynamic adjustments to process priorities.
[Link]:
68
Priority scheduling allows processes to be scheduled based on assigned priority levels, ensuring that higher-priority tasks are executed before lower-priority ones. This can be beneficial for critical tasks that need immediate attention, as they can preempt lower-priority processes . However, this approach can lead to problems such as starvation, where lower-priority processes may never get scheduled if higher-priority processes continuously enter the system. This potential for indefinite waiting can lead to lower-priority processes being neglected, which may not be suitable for all environments, particularly when fairness among processes is required .
Context switching plays a crucial role in multitasking by allowing multiple processes to share the CPU effectively. During a context switch, the current state of a process, including its CPU registers and program counter, is saved in its PCB, and the state of the next scheduled process is loaded from its PCB. This mechanism enables the operating system to suspend and resume processes, ensuring efficient CPU utilization . However, context switches introduce overhead due to the time required to save and load process states. Frequent switching can degrade system performance as more CPU time is spent managing processes rather than executing them, particularly in systems with numerous context switches due to small time quanta in scheduling algorithms like Round Robin .
The design and implementation of PCBs contribute to the stability and efficiency of an operating system by organizing all necessary information about processes in a structured manner. Each PCB stores critical data like process state, memory usage, and scheduling information, allowing the OS to manage processes comprehensively and efficiently . This organization aids in smooth process scheduling, context switching, and resource management, which are essential for stable and efficient system operation. However, the complexity associated with managing numerous PCBs and the memory overhead they require can challenge system scalability and responsiveness, indicating a delicate balance must be maintained between organizational efficiency and system complexity .
The Process Control Block (PCB) provides several advantages for process management. It organizes critical information about a process, such as memory usage and CPU scheduling details, which helps the OS schedule processes efficiently and perform context switching smoothly. This results in optimized CPU usage and efficient multitasking . However, maintaining a PCB for each process increases memory usage and adds complexity to the operating system, especially as the number of processes grows. This can slow down performance, and the added complexity makes it challenging to scale and manage processes .
Round Robin scheduling ensures fairness by giving each process an equal time slice or quantum to execute, rotating through processes in a cyclic order. This approach prevents any single process from dominating CPU time, fostering a balanced execution environment . However, the trade-offs involve increased system overhead due to frequent context switches, especially if the time quantum is small. This can lead to lower throughput, as more CPU cycles are spent on managing processes rather than executing them. The need to manage the size of the time quantum carefully is crucial, as a very small quantum can cause excessive overhead, while a very large one can diminish the responsiveness intended by this scheduling technique .
The Multilevel Feedback Queue (MLFQ) prevents process starvation through a mechanism known as aging, where the priority of long-waiting processes is gradually increased. By adjusting priorities dynamically based on execution patterns, MLFQ ensures that processes with lower initial priorities eventually receive the CPU time they need, thereby preventing indefinite postponement . This prevention of starvation is critical for system performance because it maintains fairness and ensures that all processes, regardless of their initial priority, can eventually complete execution. This balance between responsiveness for high-priority tasks and fairness for all tasks enhances overall system stability and user satisfaction .
Multilevel Feedback Queue (MLFQ) scheduling introduced dynamic priority adjustment and the ability for processes to move between different priority queues based on their behavior. This flexibility allows the system to respond more dynamically to different process needs, improving responsiveness particularly for interactive applications. Unlike Multilevel Queue (MLQ) scheduling, where processes are fixed in a single queue, MLFQ adjusts a process's priority over time based on its execution history. This means if a process consumes significant CPU resources, its priority might be lowered, while interactive processes waiting too long might gain priority, thus enhancing overall responsiveness and ensuring critical tasks receive timely execution .
The Operating System uses the Process Control Block (PCB) to manage different states of a process effectively. The PCB records the current state of a process, which can be "running," "ready," "waiting," or "terminated." The information in the PCB allows the OS to schedule processes appropriately based on their state. For example, a process in the "ready" state may be scheduled to run next, while one in the "waiting" state is paused until its required event occurs. Additionally, context switching is facilitated by the PCB; when a process is paused, its state, including CPU registers and the program counter, is saved in the PCB, allowing the OS to resume it correctly later .
The PCB aids in resource sharing by keeping track of the resources each process is using, such as memory allocations and open files. This information facilitates the OS in managing how resources can be shared or accessed by other processes, ensuring resource conflicts are minimized . Additionally, for synchronization, the PCB records status information that can help the OS manage inter-process communication and coordinate access to shared resources efficiently. This ensures that processes can interact smoothly without deadlocks or race conditions, enhancing overall system stability and efficiency .
The stack is a part of a computer's memory that holds temporary data necessary for the execution of processes. It is dynamically managed, growing and shrinking as functions are called and completed. Its key roles include storing function parameters, return addresses, and local variables. When a function is called, the stack allocates space for these, ensuring that the program can return to the correct point after a function execution and that each function has the correct input data to operate. This dynamic nature and structured management of data allows the stack to facilitate function execution and return in an efficient and orderly manner .