SlideShare a Scribd company logo
UNIT 2
PROCESS
MANAGEMENT
By Apurva Bijawe
PROCESS
• A process is a program in execution. For example, when we write a program in C or
C++ and compile it, the compiler creates binary code. The original code and binary
code are both programs.
• When we actually run the binary code, it becomes a process.
• A process is an ‘active’ entity instead of a program, which is considered a ‘passive’
entity.
• A single program can create many processes when run multiple times; for example,
when we open a .exe or binary file multiple times, multiple instances begin (multiple
processes are created).
WHAT IS PROCESS?
2
PROCESSES USUALLY FALL INTO TWO CATEGORIES
1. System processes
• System processes are started by the operating system, and they usually have
something to do with running the OS itself.
2. User processes
• User processes, as you might guess, are those that the user starts. The operating
system though handles various system processes, but it mainly handles the user code
execution.
• Each process can run independently of other processes and have its own memory
space. This makes process management tricky, as the OS needs to ensure that each
process gets its fair share of resources (memory, CPU time, etc.) while ensuring that
the system remains stable.
3
WHAT IS PROCESS MANAGEMENT?
• It is an important part of the operating system.
• It allows you to control the way your computer runs by managing the currently active
processes. This includes ending processes that are no longer needed, setting process priorities,
and more.
4
PROCESS STATES
5
• The process, from its creation to completion, passes through various states. The
minimum number of states is five.
• The names of the states are not standardized although the process may be in one of the
following states during execution.
1. New
• A program which is going to be picked up by the OS into the main memory is called a
new process.
2. Ready
• Whenever a process is created, it directly enters in the ready state, in which, it waits for
the CPU to be assigned. The OS picks the new processes from the secondary memory
and put all of them in the main memory.
• The processes which are ready for the execution and reside in the main memory are
called ready state processes. There can be many processes present in the ready state.
6
3. Running
• One of the processes from the ready state will be chosen by the OS depending upon
the scheduling algorithm. Hence, if we have only one CPU in our system, the number
of running processes for a particular time will always be one. If we have n processors
in the system then we can have n processes running simultaneously.
4. Block or wait
• From the Running state, a process can make the transition to the block or wait state
depending upon the scheduling algorithm or the intrinsic behavior of the process.
• When a process waits for a certain resource to be assigned or for the input from the
user then the OS move this process to the block or wait state and assigns the CPU to
the other processes.
5. Completion or termination
• When a process finishes its execution, it comes in the termination state. All the context
of the process (Process Control Block) will also be deleted the process will be
terminated by the Operating system.
7
6. Suspend ready
• A process in the ready state, which is moved to secondary memory from the
main memory due to lack of the resources (mainly primary memory) is called in
the suspend ready state.
• If the main memory is full and a higher priority process comes for the execution
then the OS have to make the room for the process in the main memory by
throwing the lower priority process out into the secondary memory. The suspend
ready processes remain in the secondary memory until the main memory gets
available.
7. Suspend wait
• Instead of removing the process from the ready queue, it's better to remove the
blocked process which is waiting for some resources in the main memory. Since
it is already waiting for some resource to get available hence it is better if it waits
in the secondary memory and make room for the higher priority process. These
processes complete their execution once the main memory gets available and
their wait is finished.
8
OPERATIONS ON THE PROCESS
1. Creation
• Once the process is created, it will be ready and come into the ready queue
(main memory) and will be ready for the execution.
2. Scheduling
• Out of the many processes present in the ready queue, the Operating system
chooses one process and start executing it. Selecting the process which is to be
executed next, is known as scheduling.
9
3. Execution
• Once the process is scheduled for the execution, the processor starts
executing it. Process may come to the blocked or wait state during the
execution then in that case the processor starts executing the other
processes.
4. Deletion/killing
• Once the purpose of the process gets over then the OS will kill the
process. The Context of the process (PCB) will be deleted and the process
gets terminated by the Operating system.
10
TYPES OF SCHEDULERS
1.Long-term – performance:
• It brings the new process to the ‘Ready State’. It controls the Degree of Multi-programming,
i.e., the number of processes present in a ready state at any point in time.
• It is important that the long-term scheduler make a careful selection of both I/O and CPU-bound
processes. I/O-bound tasks are which use much of their time in input and output operations
while CPU-bound processes are which spend their time on the CPU.
• The job scheduler increases efficiency by maintaining a balance between the two. They operate
at a high level and are typically used in batch-processing systems
• A long-term scheduler, also known as a job scheduler, is an operating system component that
determines which processes should be admitted to the system and when.
• The long-term scheduler is in charge of allocating resources such as processor time and
memory to processes based on their needs and priorities. It also determines the order in which
processes are executed and manages the execution of processes that may take a long time to
complete, such as batch jobs or background tasks
11
FUNCTIONS OF LONG-TERM SCHEDULER
• Long-term schedulers are in charge of determining the order in which processes are
executed and managing the execution of processes that may take a long time to
complete, such as batch jobs or background tasks.
• A long-term scheduler’s primary function is to minimize processing time by taking the
mixtures of CPU-bound jobs and I/O-bound jobs.
• CPU Bound Jobs: CPU-bound jobs are tasks or processes that necessitate a significant
amount of CPU processing time and resources (Central Processing Unit). These jobs can
put a significant strain on the CPU, affecting system performance and responsiveness.
• I/O Bound Jobs: I/O bound jobs are tasks or processes that necessitate a large number of
input/output (I/O) operations, such as reading and writing to discs or networks. These jobs
are less dependent on the CPU and can put a greater strain on the system’s I/O
subsystem.
12
13
2.Short-term – Context switching time: It is responsible for selecting one
process from the ready state for scheduling it on the running state. Note:
Short-term scheduler only selects the process to schedule it doesn’t load the
process on running. Short-term scheduler will decide which process is to be
executed next and then it will call the dispatcher. A dispatcher is a software
that moves the process from ready to run and vice versa. In other words, it
is context switching. It runs frequently. Short-term scheduler is also called
CPU scheduler.
• Medium-term – Swapping time: Typically, processes that are blocked or
waiting must be managed by the medium-term scheduler.
• Suspension decision is taken by the medium-term scheduler. The medium-term
scheduler is used for swapping which is moving the process from main memory
to secondary and vice versa. The swapping is done to reduce degree of
multiprogramming.
14
15
COMPARISON AMONG SCHEDULER
LongTerm Scheduler Short term schedular
MediumTerm
Scheduler
• It is a job scheduler It is a CPU scheduler
It is a process-swapping
scheduler.
• Generally, Speed is
lesser than short
term scheduler
Speed is the fastest
among all of them.
Speed lies in between
both short and long-
term schedulers.
• It controls the
degree of
multiprogramming
It gives less control over
how much
multiprogramming is
done.
It reduces the degree of
multiprogramming.
16
• It is barely present or
nonexistent in the
time-sharing system.
It is a minimal time-
sharing system.
It is a component of
systems for time sharing.
• It can re-enter the
process into memory,
allowing for the
continuation of
execution.
It selects those
processes which are
ready to execute
It can re-introduce the
process into memory
and execution can be
continued.
WHAT IS PROCESS CONTROL BLOCK (PCB)?
• Process Control Block is a data structure that contains information of the process
related to it. The process control block is also known as a task control block,
entry of the process table, etc.
• While creating a process, the operating system performs several operations. To identify
the processes, it assigns a process identification number (PID) to each process.
• As the operating system supports multi-programming, it needs to keep track of all the
processes. For this task, the process control block (PCB) is used to track the process’s
execution status. Each block of memory contains information about the process state,
program counter, stack pointer, status of opened files, scheduling algorithms, etc.
• All this information is required and must be saved when the process is switched from one
state to another. When the process makes a transition from one state to another, the
operating system must update information in the process’s PCB. A process control block
(PCB) contains information about the process, i.e. registers, quantum, priority, etc.
17
STRUCTURE OF THE PROCESS CONTROL BLOCK
18
SOME OF DATA ITEMS:
1.Process State
• This specifies the process state i.e. new, ready, running, waiting or terminated.
2.Process Number
• This shows the number of the particular process.
3.Program Counter
• This contains the address of the next instruction that needs to be executed in
the process.
4.Registers
• This specifies the registers that are used by the process. They may
include accumulators, index registers, stack pointers, general purpose registers etc.
5.List of Open Files
• These are the different files that are associated with the process
19
6. CPU Scheduling Information
• The process priority, pointers to scheduling queues etc. is the CPU scheduling information that is
contained in the PCB. This may also include any other scheduling parameters.
7.Memory Management Information
• The memory management information includes the page tables or the segment tables
depending on the memory system used. It also contains the value of the base registers, limit
registers etc.
8.I/O Status Information
• This information includes the list of I/O devices used by the process, the list of files etc.
9.Accounting information
• The time limits, account numbers, amount of CPU used, process numbers etc. are all a part of
the PCB accounting information.
10.Location of the Process Control Block
• The process control block is kept in a memory area that is protected from the normal user
access. This is done because it contains important process information. Some of the operating
systems place the PCB at the beginning of the kernel stack for the process as it is a safe
location.
20
PROCESSES ANDTHREADS
• Processes:
• A process is a program in execution. It consists of:
1.Program Counter (PC): Indicates the address of the next instruction to be executed.
2.Registers: Contain various data, including the current status of the process.
3.Memory Space: Includes code, data, and a stack.
• Key characteristics of processes:
• Isolation: Processes are isolated from each other, meaning one process cannot directly
access the memory of another.
• Independence: Processes operate independently, and the failure of one process does not
affect others.
• Resource Allocation: Each process has its own system resources, such as memory space,
file descriptors, etc.
21
• Threads:
• A thread is a basic unit of CPU utilization within a process. A process can have
multiple threads, and these threads share the same resources (like memory
space) but run independently. Threads within the same process can
communicate more easily than separate processes.
• Key characteristics of threads:
• Shared Resources: Threads within the same process share resources like code,
data, and files.
• Fast Communication: Inter-thread communication is faster than inter-process
communication since threads share the same memory space.
• Lightweight: Threads are generally more lightweight than processes, as they
share resources.
22
The process can be split down into so many threads.
For example, in a browser, many tabs can be viewed as threads.
MS Word uses many threads - formatting text from one thread,
processing input from another thread, etc.
Multithreading in Operating System
• A multithreading operating system is one that allows multiple threads to execute concurrently
within a single process. This type of OS takes advantage of CPU cores with multiple threads,
dividing process execution efficiently to increase the performance of multi-core processors.
Each thread runs a part of a process's workload, making the overall execution faster and more
efficient.
• In such systems, context switching between threads is typically faster than between processes,
as threads share the same memory space and resources, whereas processes do not. This
sharing enables threads to communicate with each other more quickly than separate
processes.
• Multithreading is beneficial for tasks that can be divided into smaller, concurrent operations,
and it's essential for modern applications that require real-time performance and high
responsiveness. This operating system design is widely used in server and desktop
applications, where it maximizes resource utilization and provides improved performance on
multi-core CPUs.
24
HOW DOES MULTITHREADING IN OS WORK?
• Multithreading in an operating system works by allowing multiple threads to exist
within the context of a single process, sharing its resources but operating
independently.
• Think of it like a team of chefs working in one kitchen; they share the same space
and utensils (the process's resources), but each chef prepares a different dish
simultaneously (the threads).
• The operating system manages these threads, scheduling them to run on the CPU
in a way that maximizes efficiency—making sure that while one chef is waiting for
the oven, another is chopping vegetables. This multitasking nature of threads can
lead to faster execution of complex tasks, better resource utilization.
25
REAL WORLD EXAMPLE OF MULTITHREADING
• Imagine you are a chef working in a busy kitchen (representing the operating
system), and you have multiple tasks to accomplish (representing processes or
threads). Each task involves preparing a different dish, and each dish has several
steps.
• Without multithreading (single-threaded model):
• You, as the chef, start preparing one dish at a time. While waiting for one dish to
cook, you are idle and cannot work on another dish.
• The kitchen is not efficiently utilized, and the overall cooking time is longer because
each dish must be completed before starting the next.
26
27
With multithreading (multithreaded model):
•You decide to use multiple cutting boards and cooking stations to work on
multiple dishes simultaneously.
•While one dish is simmering on the stove, you are chopping vegetables for
another dish or preparing ingredients for a third dish.
•This allows you to make progress on multiple tasks concurrently, making better
use of your time and the kitchen resources.
•As one dish is completed, you can move on to the next without waiting for the
others to finish.
28
In this analogy:
Each dish is analogous to a thread or process.
The chef represents the operating system.
The kitchen resources (cutting boards, cooking stations) represent the CPU and other
system resources.
Multithreading in the operating system works similarly. Multiple threads or processes
can execute concurrently, allowing for better resource utilization and improved
overall system performance. Each thread can perform a specific task independently,
and the operating system manages their execution, scheduling them to run on the
available CPU cores efficiently.
ADVANTAGES OF MULTITHREADING OPERATING SYSTEM
• Resource sharing: Because threads can share any process memory and resources, every
program can perform several tasks inside the same address space.
• Multiple Processor Architecture: Different threads can execute in parallel on many
processors, allowing for high processor usage and efficiency.
• Reduced Context Switching Time: As with Thread Context Switching, the threads
reduce context switching time while keeping the virtual memory space the same.
• Cost-effective: Allocating memory and resources throughout the process generation
process has a cost. Context-switch threads are more affordable to construct since they can
distribute process resources.
29
DISADVANTAGES OF MULTITHREADING OPERATING SYSTEM
1. Complexity and Synchronization
• Multithreading introduces complexity into program design and implementation. Coordinating
and synchronizing threads to avoid race conditions, deadlocks, and other concurrency-related
issues can be challenging.
• Debugging multithreaded programs can be more difficult due to the non-deterministic nature
of thread execution.
2. Race Conditions
• Race conditions occur when multiple threads access shared data concurrently without proper
synchronization, leading to unpredictable and erroneous behavior.
• Ensuring data consistency and avoiding race conditions requires careful use of
synchronization mechanisms like locks and semaphores.
30
31
3. Deadlocks:
•A deadlock is a situation where two or more threads are unable to proceed
because each is waiting for the other to release a resource. Deadlocks can
lead to a complete system halt.
•Designing systems to avoid deadlocks requires a good understanding of
resource allocation and proper use of synchronization.
4. Thread Starvation and Priority Inversion:
•Thread starvation occurs when a thread is unable to access resources or
CPU time, potentially leading to poor performance.
•Priority inversion occurs when a low-priority thread holds a resource
needed by a high-priority thread, leading to the inversion of execution
priorities.

More Related Content

PDF
OVERVIEW OF OPERATING SYSTEM -Basic concepts of operating system like functio...
PPT
Operating system services 9
PPTX
Process state in OS
PPT
introduction To Operating System
PPT
Chapter 1: Introduction to Operating System
PDF
OS - Process Concepts
DOCX
Opetating System Memory management
PPTX
Distributed Shared Memory notes in distributed systems.pptx
OVERVIEW OF OPERATING SYSTEM -Basic concepts of operating system like functio...
Operating system services 9
Process state in OS
introduction To Operating System
Chapter 1: Introduction to Operating System
OS - Process Concepts
Opetating System Memory management
Distributed Shared Memory notes in distributed systems.pptx

What's hot (20)

PPTX
kernels
PPTX
Process in operating system
PPTX
Thread scheduling in Operating Systems
PPT
Mutual exclusion and sync
PPTX
SCHEDULING ALGORITHMS
PPTX
Batch operating system
PPTX
How Operating system works.
PPTX
System program
PPTX
Message passing ( in computer science)
PPTX
Cpu scheduling
PPT
Windows Kernel-
PPT
Operating system presentation
PPT
Services provided by os
PPTX
Operating Systems - Processor Management
PPTX
Evolution of os
PPT
Functions of Operating Systems
PPT
Memory management
PPTX
chapter 1 introduction to operating system
kernels
Process in operating system
Thread scheduling in Operating Systems
Mutual exclusion and sync
SCHEDULING ALGORITHMS
Batch operating system
How Operating system works.
System program
Message passing ( in computer science)
Cpu scheduling
Windows Kernel-
Operating system presentation
Services provided by os
Operating Systems - Processor Management
Evolution of os
Functions of Operating Systems
Memory management
chapter 1 introduction to operating system
Ad

Similar to Process management- This ppt contains all required information regarding operating system processes, threads. (20)

PPTX
Os unit 3 , process management
PPTX
Unit 2_OS process management
PPTX
Operating System.pptx
PDF
Operating System-Concepts of Process
PPTX
UNIT I-Processes.pptx
PPTX
Operating System Periodic Test 1 Answers.pptx
PPTX
Operating System Periodic test answers t
PPTX
Operating System Periodic Test 1 Answers
PPTX
Process management1
PPTX
Process management system in operating system
PPTX
Process management in operating system, process creation, process sheduling
PPTX
52bf066dbfcc4d739fa99d255dba287a.pptx
PPTX
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptx
PPTX
PROCESS.pptx
PPTX
Unit 2...............................................
PPTX
introduction to operating system unit 2
PPTX
Process Management of Operating Systems.
PPTX
UNIT 2 OS.pptx Introduction of Operating System
DOC
Operating Systems Unit Two - Fourth Semester - Engineering
PDF
Process And Scheduling Algorithms in os
Os unit 3 , process management
Unit 2_OS process management
Operating System.pptx
Operating System-Concepts of Process
UNIT I-Processes.pptx
Operating System Periodic Test 1 Answers.pptx
Operating System Periodic test answers t
Operating System Periodic Test 1 Answers
Process management1
Process management system in operating system
Process management in operating system, process creation, process sheduling
52bf066dbfcc4d739fa99d255dba287a.pptx
CPU Scheduling Criteria CPU Scheduling Criteria (1).pptx
PROCESS.pptx
Unit 2...............................................
introduction to operating system unit 2
Process Management of Operating Systems.
UNIT 2 OS.pptx Introduction of Operating System
Operating Systems Unit Two - Fourth Semester - Engineering
Process And Scheduling Algorithms in os
Ad

Recently uploaded (20)

PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPT
Project quality management in manufacturing
PPTX
additive manufacturing of ss316l using mig welding
PDF
PPT on Performance Review to get promotions
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Sustainable Sites - Green Building Construction
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Digital Logic Computer Design lecture notes
PPT
Mechanical Engineering MATERIALS Selection
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
web development for engineering and engineering
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Well-logging-methods_new................
Model Code of Practice - Construction Work - 21102022 .pdf
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Project quality management in manufacturing
additive manufacturing of ss316l using mig welding
PPT on Performance Review to get promotions
bas. eng. economics group 4 presentation 1.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Sustainable Sites - Green Building Construction
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Digital Logic Computer Design lecture notes
Mechanical Engineering MATERIALS Selection
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
web development for engineering and engineering
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Well-logging-methods_new................

Process management- This ppt contains all required information regarding operating system processes, threads.

  • 2. PROCESS • A process is a program in execution. For example, when we write a program in C or C++ and compile it, the compiler creates binary code. The original code and binary code are both programs. • When we actually run the binary code, it becomes a process. • A process is an ‘active’ entity instead of a program, which is considered a ‘passive’ entity. • A single program can create many processes when run multiple times; for example, when we open a .exe or binary file multiple times, multiple instances begin (multiple processes are created). WHAT IS PROCESS? 2
  • 3. PROCESSES USUALLY FALL INTO TWO CATEGORIES 1. System processes • System processes are started by the operating system, and they usually have something to do with running the OS itself. 2. User processes • User processes, as you might guess, are those that the user starts. The operating system though handles various system processes, but it mainly handles the user code execution. • Each process can run independently of other processes and have its own memory space. This makes process management tricky, as the OS needs to ensure that each process gets its fair share of resources (memory, CPU time, etc.) while ensuring that the system remains stable. 3
  • 4. WHAT IS PROCESS MANAGEMENT? • It is an important part of the operating system. • It allows you to control the way your computer runs by managing the currently active processes. This includes ending processes that are no longer needed, setting process priorities, and more. 4
  • 6. • The process, from its creation to completion, passes through various states. The minimum number of states is five. • The names of the states are not standardized although the process may be in one of the following states during execution. 1. New • A program which is going to be picked up by the OS into the main memory is called a new process. 2. Ready • Whenever a process is created, it directly enters in the ready state, in which, it waits for the CPU to be assigned. The OS picks the new processes from the secondary memory and put all of them in the main memory. • The processes which are ready for the execution and reside in the main memory are called ready state processes. There can be many processes present in the ready state. 6
  • 7. 3. Running • One of the processes from the ready state will be chosen by the OS depending upon the scheduling algorithm. Hence, if we have only one CPU in our system, the number of running processes for a particular time will always be one. If we have n processors in the system then we can have n processes running simultaneously. 4. Block or wait • From the Running state, a process can make the transition to the block or wait state depending upon the scheduling algorithm or the intrinsic behavior of the process. • When a process waits for a certain resource to be assigned or for the input from the user then the OS move this process to the block or wait state and assigns the CPU to the other processes. 5. Completion or termination • When a process finishes its execution, it comes in the termination state. All the context of the process (Process Control Block) will also be deleted the process will be terminated by the Operating system. 7
  • 8. 6. Suspend ready • A process in the ready state, which is moved to secondary memory from the main memory due to lack of the resources (mainly primary memory) is called in the suspend ready state. • If the main memory is full and a higher priority process comes for the execution then the OS have to make the room for the process in the main memory by throwing the lower priority process out into the secondary memory. The suspend ready processes remain in the secondary memory until the main memory gets available. 7. Suspend wait • Instead of removing the process from the ready queue, it's better to remove the blocked process which is waiting for some resources in the main memory. Since it is already waiting for some resource to get available hence it is better if it waits in the secondary memory and make room for the higher priority process. These processes complete their execution once the main memory gets available and their wait is finished. 8
  • 9. OPERATIONS ON THE PROCESS 1. Creation • Once the process is created, it will be ready and come into the ready queue (main memory) and will be ready for the execution. 2. Scheduling • Out of the many processes present in the ready queue, the Operating system chooses one process and start executing it. Selecting the process which is to be executed next, is known as scheduling. 9
  • 10. 3. Execution • Once the process is scheduled for the execution, the processor starts executing it. Process may come to the blocked or wait state during the execution then in that case the processor starts executing the other processes. 4. Deletion/killing • Once the purpose of the process gets over then the OS will kill the process. The Context of the process (PCB) will be deleted and the process gets terminated by the Operating system. 10
  • 11. TYPES OF SCHEDULERS 1.Long-term – performance: • It brings the new process to the ‘Ready State’. It controls the Degree of Multi-programming, i.e., the number of processes present in a ready state at any point in time. • It is important that the long-term scheduler make a careful selection of both I/O and CPU-bound processes. I/O-bound tasks are which use much of their time in input and output operations while CPU-bound processes are which spend their time on the CPU. • The job scheduler increases efficiency by maintaining a balance between the two. They operate at a high level and are typically used in batch-processing systems • A long-term scheduler, also known as a job scheduler, is an operating system component that determines which processes should be admitted to the system and when. • The long-term scheduler is in charge of allocating resources such as processor time and memory to processes based on their needs and priorities. It also determines the order in which processes are executed and manages the execution of processes that may take a long time to complete, such as batch jobs or background tasks 11
  • 12. FUNCTIONS OF LONG-TERM SCHEDULER • Long-term schedulers are in charge of determining the order in which processes are executed and managing the execution of processes that may take a long time to complete, such as batch jobs or background tasks. • A long-term scheduler’s primary function is to minimize processing time by taking the mixtures of CPU-bound jobs and I/O-bound jobs. • CPU Bound Jobs: CPU-bound jobs are tasks or processes that necessitate a significant amount of CPU processing time and resources (Central Processing Unit). These jobs can put a significant strain on the CPU, affecting system performance and responsiveness. • I/O Bound Jobs: I/O bound jobs are tasks or processes that necessitate a large number of input/output (I/O) operations, such as reading and writing to discs or networks. These jobs are less dependent on the CPU and can put a greater strain on the system’s I/O subsystem. 12
  • 13. 13 2.Short-term – Context switching time: It is responsible for selecting one process from the ready state for scheduling it on the running state. Note: Short-term scheduler only selects the process to schedule it doesn’t load the process on running. Short-term scheduler will decide which process is to be executed next and then it will call the dispatcher. A dispatcher is a software that moves the process from ready to run and vice versa. In other words, it is context switching. It runs frequently. Short-term scheduler is also called CPU scheduler.
  • 14. • Medium-term – Swapping time: Typically, processes that are blocked or waiting must be managed by the medium-term scheduler. • Suspension decision is taken by the medium-term scheduler. The medium-term scheduler is used for swapping which is moving the process from main memory to secondary and vice versa. The swapping is done to reduce degree of multiprogramming. 14
  • 15. 15 COMPARISON AMONG SCHEDULER LongTerm Scheduler Short term schedular MediumTerm Scheduler • It is a job scheduler It is a CPU scheduler It is a process-swapping scheduler. • Generally, Speed is lesser than short term scheduler Speed is the fastest among all of them. Speed lies in between both short and long- term schedulers. • It controls the degree of multiprogramming It gives less control over how much multiprogramming is done. It reduces the degree of multiprogramming.
  • 16. 16 • It is barely present or nonexistent in the time-sharing system. It is a minimal time- sharing system. It is a component of systems for time sharing. • It can re-enter the process into memory, allowing for the continuation of execution. It selects those processes which are ready to execute It can re-introduce the process into memory and execution can be continued.
  • 17. WHAT IS PROCESS CONTROL BLOCK (PCB)? • Process Control Block is a data structure that contains information of the process related to it. The process control block is also known as a task control block, entry of the process table, etc. • While creating a process, the operating system performs several operations. To identify the processes, it assigns a process identification number (PID) to each process. • As the operating system supports multi-programming, it needs to keep track of all the processes. For this task, the process control block (PCB) is used to track the process’s execution status. Each block of memory contains information about the process state, program counter, stack pointer, status of opened files, scheduling algorithms, etc. • All this information is required and must be saved when the process is switched from one state to another. When the process makes a transition from one state to another, the operating system must update information in the process’s PCB. A process control block (PCB) contains information about the process, i.e. registers, quantum, priority, etc. 17
  • 18. STRUCTURE OF THE PROCESS CONTROL BLOCK 18
  • 19. SOME OF DATA ITEMS: 1.Process State • This specifies the process state i.e. new, ready, running, waiting or terminated. 2.Process Number • This shows the number of the particular process. 3.Program Counter • This contains the address of the next instruction that needs to be executed in the process. 4.Registers • This specifies the registers that are used by the process. They may include accumulators, index registers, stack pointers, general purpose registers etc. 5.List of Open Files • These are the different files that are associated with the process 19
  • 20. 6. CPU Scheduling Information • The process priority, pointers to scheduling queues etc. is the CPU scheduling information that is contained in the PCB. This may also include any other scheduling parameters. 7.Memory Management Information • The memory management information includes the page tables or the segment tables depending on the memory system used. It also contains the value of the base registers, limit registers etc. 8.I/O Status Information • This information includes the list of I/O devices used by the process, the list of files etc. 9.Accounting information • The time limits, account numbers, amount of CPU used, process numbers etc. are all a part of the PCB accounting information. 10.Location of the Process Control Block • The process control block is kept in a memory area that is protected from the normal user access. This is done because it contains important process information. Some of the operating systems place the PCB at the beginning of the kernel stack for the process as it is a safe location. 20
  • 21. PROCESSES ANDTHREADS • Processes: • A process is a program in execution. It consists of: 1.Program Counter (PC): Indicates the address of the next instruction to be executed. 2.Registers: Contain various data, including the current status of the process. 3.Memory Space: Includes code, data, and a stack. • Key characteristics of processes: • Isolation: Processes are isolated from each other, meaning one process cannot directly access the memory of another. • Independence: Processes operate independently, and the failure of one process does not affect others. • Resource Allocation: Each process has its own system resources, such as memory space, file descriptors, etc. 21
  • 22. • Threads: • A thread is a basic unit of CPU utilization within a process. A process can have multiple threads, and these threads share the same resources (like memory space) but run independently. Threads within the same process can communicate more easily than separate processes. • Key characteristics of threads: • Shared Resources: Threads within the same process share resources like code, data, and files. • Fast Communication: Inter-thread communication is faster than inter-process communication since threads share the same memory space. • Lightweight: Threads are generally more lightweight than processes, as they share resources. 22
  • 23. The process can be split down into so many threads. For example, in a browser, many tabs can be viewed as threads. MS Word uses many threads - formatting text from one thread, processing input from another thread, etc.
  • 24. Multithreading in Operating System • A multithreading operating system is one that allows multiple threads to execute concurrently within a single process. This type of OS takes advantage of CPU cores with multiple threads, dividing process execution efficiently to increase the performance of multi-core processors. Each thread runs a part of a process's workload, making the overall execution faster and more efficient. • In such systems, context switching between threads is typically faster than between processes, as threads share the same memory space and resources, whereas processes do not. This sharing enables threads to communicate with each other more quickly than separate processes. • Multithreading is beneficial for tasks that can be divided into smaller, concurrent operations, and it's essential for modern applications that require real-time performance and high responsiveness. This operating system design is widely used in server and desktop applications, where it maximizes resource utilization and provides improved performance on multi-core CPUs. 24
  • 25. HOW DOES MULTITHREADING IN OS WORK? • Multithreading in an operating system works by allowing multiple threads to exist within the context of a single process, sharing its resources but operating independently. • Think of it like a team of chefs working in one kitchen; they share the same space and utensils (the process's resources), but each chef prepares a different dish simultaneously (the threads). • The operating system manages these threads, scheduling them to run on the CPU in a way that maximizes efficiency—making sure that while one chef is waiting for the oven, another is chopping vegetables. This multitasking nature of threads can lead to faster execution of complex tasks, better resource utilization. 25
  • 26. REAL WORLD EXAMPLE OF MULTITHREADING • Imagine you are a chef working in a busy kitchen (representing the operating system), and you have multiple tasks to accomplish (representing processes or threads). Each task involves preparing a different dish, and each dish has several steps. • Without multithreading (single-threaded model): • You, as the chef, start preparing one dish at a time. While waiting for one dish to cook, you are idle and cannot work on another dish. • The kitchen is not efficiently utilized, and the overall cooking time is longer because each dish must be completed before starting the next. 26
  • 27. 27 With multithreading (multithreaded model): •You decide to use multiple cutting boards and cooking stations to work on multiple dishes simultaneously. •While one dish is simmering on the stove, you are chopping vegetables for another dish or preparing ingredients for a third dish. •This allows you to make progress on multiple tasks concurrently, making better use of your time and the kitchen resources. •As one dish is completed, you can move on to the next without waiting for the others to finish.
  • 28. 28 In this analogy: Each dish is analogous to a thread or process. The chef represents the operating system. The kitchen resources (cutting boards, cooking stations) represent the CPU and other system resources. Multithreading in the operating system works similarly. Multiple threads or processes can execute concurrently, allowing for better resource utilization and improved overall system performance. Each thread can perform a specific task independently, and the operating system manages their execution, scheduling them to run on the available CPU cores efficiently.
  • 29. ADVANTAGES OF MULTITHREADING OPERATING SYSTEM • Resource sharing: Because threads can share any process memory and resources, every program can perform several tasks inside the same address space. • Multiple Processor Architecture: Different threads can execute in parallel on many processors, allowing for high processor usage and efficiency. • Reduced Context Switching Time: As with Thread Context Switching, the threads reduce context switching time while keeping the virtual memory space the same. • Cost-effective: Allocating memory and resources throughout the process generation process has a cost. Context-switch threads are more affordable to construct since they can distribute process resources. 29
  • 30. DISADVANTAGES OF MULTITHREADING OPERATING SYSTEM 1. Complexity and Synchronization • Multithreading introduces complexity into program design and implementation. Coordinating and synchronizing threads to avoid race conditions, deadlocks, and other concurrency-related issues can be challenging. • Debugging multithreaded programs can be more difficult due to the non-deterministic nature of thread execution. 2. Race Conditions • Race conditions occur when multiple threads access shared data concurrently without proper synchronization, leading to unpredictable and erroneous behavior. • Ensuring data consistency and avoiding race conditions requires careful use of synchronization mechanisms like locks and semaphores. 30
  • 31. 31 3. Deadlocks: •A deadlock is a situation where two or more threads are unable to proceed because each is waiting for the other to release a resource. Deadlocks can lead to a complete system halt. •Designing systems to avoid deadlocks requires a good understanding of resource allocation and proper use of synchronization. 4. Thread Starvation and Priority Inversion: •Thread starvation occurs when a thread is unable to access resources or CPU time, potentially leading to poor performance. •Priority inversion occurs when a low-priority thread holds a resource needed by a high-priority thread, leading to the inversion of execution priorities.