0% found this document useful (0 votes)
3 views

Process Management

The document discusses key concepts in process management, including Process Control Blocks (PCBs), context switching, process scheduling, interprocess communication (IPC), and multithreading. It explains how PCBs store essential information about processes, the steps involved in context switching, and various scheduling algorithms used to manage CPU resources efficiently. Additionally, it covers IPC mechanisms for communication between processes and the benefits and challenges of using threads and multithreading in programming.

Uploaded by

amarjeetlpu77
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Process Management

The document discusses key concepts in process management, including Process Control Blocks (PCBs), context switching, process scheduling, interprocess communication (IPC), and multithreading. It explains how PCBs store essential information about processes, the steps involved in context switching, and various scheduling algorithms used to manage CPU resources efficiently. Additionally, it covers IPC mechanisms for communication between processes and the benefits and challenges of using threads and multithreading in programming.

Uploaded by

amarjeetlpu77
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

PROCESS

MANAGEMENT
Process control block, Context switching, Process scheduling,
Interprocess communication, Threads and Multithreading
PROCESS CONTROL BLOCK(PCB)
A Process Control Block (PCB), also known as a Task Control Block or
Task Struct, is a data structure used by computer operating systems to
manage information about a process or task.

The PCB is an essential part of a multitasking operating system as it


contains crucial information about the state of a process and allows
the operating system to control and manage the execution of
processes.
The PCB typically includes the
following information:
Process ID (PID): A unique identifier assigned to each process to
distinguish it from others.

Program Counter (PC): The address of the next instruction to be executed


by the process.

CPU Registers: The content of the processor's registers, including data and
address registers.

CPU Scheduling Information: Information about the process's priority,


scheduling state, and other scheduling-related parameters.
Memory Management Information: Information about the memory allocated to
the process, such as base and limit registers, page tables, or segment tables.

I/O Status Information: The status of open files, I/O devices, and other resources
the process may be using.

Accounting Information: Information for accounting purposes, such as CPU time


used, execution time, etc.

Pointer to the Parent Process: A reference to the parent process, especially


useful in process hierarchies.

Process State: The current state of the process, such as running, ready, waiting,
etc.
When a context switch occurs (i.e., the operating system switches
from running one process to another), the contents of the CPU
registers and other relevant information are saved in the PCB of the
currently running process, and the PCB of the next process to be
executed is loaded.

This allows the operating system to maintain the illusion of


concurrent execution for multiple processes.
CONTEXT SWITCHING
Context switching is a process performed by the operating system to
switch the execution context from one process to another.

In a multitasking or multi-user operating system, multiple processes


or tasks are running concurrently, sharing the CPU time.

Context switching allows the operating system to save the state of


the currently running process and restore the state of a different
process so that it can continue execution.
Here's a step-by-step overview of
the context switching process:
Save Current Context:
The operating system saves the context of the currently running process. This
includes the contents of CPU registers, program counter, and other relevant
information about the process's state.
This information is typically saved in the Process Control Block (PCB)
associated with the current process.

Update Process Control Block (PCB):


If the current process is not terminating, its PCB is updated to reflect its
current state.
Select a New Process:
The operating system's scheduler selects a new process to run. This process
could be in the ready state or waiting for an event to occur.

Load Context of New Process:


The operating system loads the context of the selected process. This involves
retrieving the saved state from the PCB of the chosen process.
The program counter is set to the address where the process left off during its
previous execution.

Resume Execution:
The CPU begins executing the instructions of the newly loaded process.
• Context switching is a fundamental mechanism for achieving
multitasking and time-sharing in modern operating systems. It allows
the illusion of simultaneous execution of multiple processes even
though only one process is actively executing on the CPU at any given
moment. Efficient context switching is crucial for system performance,
and the overhead associated with context switching should be
minimized to ensure responsiveness and effective utilization of system
resources.
PROCESS SCHEDULING
Process scheduling
Process scheduling is a key component of operating systems that
manage multiple processes concurrently.
It involves selecting the next process to execute from the pool of
ready processes.
The primary goal of process scheduling is to use the CPU efficiently,
ensuring fair access to resources and providing responsive services to
users.
Here are the main concepts and
algorithms related to process
scheduling:
Scheduler Types:
Long-Term Scheduler (Job Scheduler): Selects processes from the job pool (e.g.,
programs on disk) and loads them into main memory for execution.
Short-Term Scheduler (CPU Scheduler): Selects processes from the ready queue
in main memory and assigns the CPU to them.

Scheduling Queues:
Job Queue: Contains all processes in the system, including those waiting to be
brought into main memory.
Ready Queue: Holds processes that are ready to execute but are waiting for the
CPU.
Blocked Queue: Contains processes that cannot proceed until a specific event
occurs (e.g., I/O completion).
Scheduling Criteria:
CPU Utilization: Maximizing CPU usage to keep the processor busy.

Throughput: The number of processes completed per unit of time.

Turnaround Time: The total time taken to execute a process, from


submission to completion.

Waiting Time: The total time a process spends waiting in the ready queue.

Response Time: The time it takes for a system to respond to a user's input.
Scheduling Algorithms:

First-Come, First-Served (FCFS): Processes are executed in the order they arrive.
Shortest Job Next (SJN) or Shortest Job First (SJF): The process with the smallest
total remaining processing time is chosen next.
Priority Scheduling: Processes are assigned priorities, and the one with the
highest priority is selected next.
Round Robin (RR): Each process is assigned a fixed time slice (quantum) to
execute before moving to the next process.
Multilevel Queue Scheduling: Processes are divided into different priority levels,
each with its own queue. Processes move between queues based on their
behavior.
Multilevel Feedback Queue Scheduling: Similar to multilevel queues, but
processes can move between queues based on their recent behavior.
Preemption:
Preemptive Scheduling: The operating system can forcefully interrupt a
currently running process to start or resume another.
Priority Inversion:
A situation where a lower-priority process holds a resource needed by a
higher-priority process, causing delays.

Effective process scheduling is crucial for maintaining system performance,


responsiveness, and fairness among competing processes. Different
scheduling algorithms are suitable for different scenarios, and the choice of
algorithm depends on the specific requirements and characteristics of the
system.
Interprocess communication
(IPC)
Interprocess communication (IPC)
Interprocess communication (IPC) refers to the mechanisms and
techniques that enable communication and data exchange between
different processes running concurrently in an operating system.

 Processes may need to communicate for various reasons, such as


sharing data, coordinating activities, or synchronizing their execution.
IPC allows processes to work together and share information in a
controlled and organized manner.

Several methods of IPC exist, and the choice depends on the specific
requirements of the tasks at hand
Here are some common IPC
mechanisms:
Pipes:
 Named Pipes (FIFO): A named pipe is a special type of file that allows processes
to communicate by reading from and writing to the same file. It provides a
simple way for processes to exchange data.
Message Passing:
 Direct or Indirect Message Passing: In direct message passing, processes
communicate directly with each other. In indirect message passing, a message is
sent to a message queue, and other processes can read from that queue.
Shared Memory:
 Memory Mapping: Processes can share a portion of their memory space,
allowing them to read and write to the shared area. Changes made by one
process are immediately visible to other processes.
Sockets:
Network Sockets: Processes on different machines can communicate over a
network using sockets. Sockets provide a communication endpoint for
processes to send and receive data.

Semaphores:
Binary Semaphores: Used for simple synchronization, allowing or denying
access to a resource.
Counting Semaphores: Allow multiple processes to access a resource
concurrently, up to a specified limit.

Mutexes (Mutual Exclusion):


Mutex (Binary Semaphore): Ensures that only one process can access a
resource at a time, preventing conflicts.
Condition Variables:
Used for signaling and synchronization between processes. One process can
signal another process to indicate that a certain condition is met.

Message Queues:
Processes can send messages to a queue, and other processes can read
messages from the queue. This provides a way for processes to communicate
asynchronously.

Remote Procedure Calls (RPC) and Remote Method Invocation


(RMI):
Allow processes to execute procedures or methods on remote machines as if
they were local.
The choice of IPC mechanism depends on factors such as the
relationship between processes, the complexity of data exchange,
performance requirements, and synchronization needs.

Different IPC methods have different trade-offs in terms of ease of


use, efficiency, and complexity.

The selection of the appropriate IPC mechanism is crucial for the


successful implementation of interprocess communication in a given
system.
Threads and Multithreading
Threads and multithreading are concepts related to concurrent
execution in computer programming.

Let's explore each concept:


Thread:
A thread is the smallest unit of execution within a process.

Threads within the same process share the same resources, such as
memory space and file descriptors, while having their own registers
and program counters.

Threads in a process share data and resources, which can simplify


communication between them.

Threads are managed by the operating system's thread scheduler.


Benefits of Threads:
Parallelism: Threads allow multiple tasks to be executed concurrently,
utilizing multiple CPU cores.

Responsiveness: In a multithreaded application, one thread can


continue execution while another is waiting for I/O, enhancing overall
responsiveness.

Resource Sharing: Threads within the same process can easily share
data, leading to efficient communication.
Multithreading:
Multithreading is a programming and execution model that allows
multiple threads to exist within the context of a single process.

Each thread represents an independent flow of execution, and


multiple threads within a process can run concurrently.

Multithreading is particularly useful for tasks that can be parallelized,


such as processing multiple tasks simultaneously.
Key Concepts:
Concurrency: Threads can execute concurrently, performing different
tasks or working on different parts of a larger task.

Synchronization: Careful synchronization mechanisms are required to


avoid conflicts when multiple threads access shared resources
simultaneously.

Communication: Threads often need to communicate with each


other to coordinate their activities. This communication may involve
shared data structures or explicit signaling mechanisms.
Advantages of Multithreading:
Improved Performance: Multithreading can lead to improved
performance, especially on systems with multiple processors or cores.

Responsive User Interfaces: Multithreading allows a program to


remain responsive to user input while performing background tasks
concurrently.

Resource Utilization: Multithreading maximizes the utilization of CPU


resources by enabling parallel execution of tasks.
Challenges of Multithreading:

Concurrency Issues: Synchronization issues, such as race conditions


and deadlocks, can arise when multiple threads access shared data.

Debugging Complexity: Debugging multithreaded programs can be


more challenging due to the potential for non-deterministic behavior
Example of Multithreading:
Consider a web browser where one thread is responsible for
rendering the user interface, another for handling user input, and
additional threads for downloading and rendering web pages.

This allows the browser to be responsive to user interactions while


performing background tasks concurrently.
In summary, threads are individual units of execution within a
process, and multithreading is a programming model that allows
multiple threads to run concurrently within the same process.

 Multithreading provides opportunities for parallelism,


responsiveness, and efficient resource sharing but requires careful
handling of concurrency and synchronization issues.
Thank You

You might also like