0% found this document useful (0 votes)
17 views20 pages

Unit 2

Uploaded by

af5803152
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views20 pages

Unit 2

Uploaded by

af5803152
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Omnamahs hivayhanumat enamah

Unit = 2
Concept of Process
❑ A process is a sequential program in execution.

❑ A process defines the fundamental unit of computation for the computer.

❑ Process contains four sections:


a. Text
b. Data
c. Heap
d. Stack
❑ Data-A process is an 'active entity' as opposed to program which is considered to be a 'passive entity’.

❑ Text -A process is more than the program code , which is sometimes known as the text section.

❑ Stack -A process generally includes the process stack, which contains temporary data (such as function
parameters, return addresses, and local variables), and a data section, which contains global variables.

❑ Heap –A process may include a heap, which is memory that is dynamically located during process
runtime.
Attributes of a Process
• PID

• List of Devices

• Type

• Size

• Memory Limits

• Priority

• State

• List of Files
process Scheduling
Process States

New: All installed processes are in known to be in new state


Ready: All processes which are waiting to run on CPU are known to be in ready state

Process States Transitions

New To Ready: When process is admitted by OS


Ready to Running: When a process is dispatched to CPU
Running to Terminated: When a process is completed
Running to Blocked: When a process goes for IO or event
Running to Ready: When a process is preempted
Blocked to Ready: When a process completes IO or event
process queues
Operating systems maintain several queues to manage processes based on their new states:

[Link] Queue: Contains all processes in the system, regardless of their state.

[Link] Queue: Holds processes that are ready to execute but are waiting for CPU availability.
. New processes are initially placed here.

[Link] queue: Comprise processes that are waiting for I/O devices to become available. Each . .
. I/O device has its own queue
Types of Schedulers
1) Long-Term Scheduler (Job)
This scheduler decides which processes are admitted to the system for processing. It controls the
degree of multiprogramming (how many processes are running concurrently).
{From new state to ready state}

2) Short-Term Scheduler (CPU)


This scheduler selects which process should be executed by the CPU from the processes that are ready
to run. It's responsible for the frequent switching between processes to give the illusion of concurrency.
{Select one of all ready processes to run}

3) Mid-Term Scheduler (Medium-term)


This scheduler handles the swapping of processes in and out of main memory. It's used to improve
performance by managing the degree of multiprogramming and balancing the workload.
{Does swapping}
cooperating process
❑ Process executing concurrently in the OS may be either independent process or cooperating
process.-
➢ A process is independent if it cannot affect or be affected by the other processes executing in
the system.
➢ Any process that does not share data with any other process is independent.
----------------------------------------------------------------------------------------------------------------------
➢ A process is cooperating if it can affect or be affected by the other process executing in the
system.
➢ Any process that share data with any other process is cooperating process.

❑ ADVANTAGES OF COOPERATING

• INFORMATION SHARING
• COMPUTATION SPEEDUP
• MODULARITY
• CONVENIENCE
INTER PROCESS COMMUNICATION

❑ Inter Process Communication (IPC) refers to a mechanism, where the operating system allow
various processes to communicate with each other.

❑ There are two models of IPC-

1. SHARED MEMORY

2. MESSAGE PASSING
1. SHARED MEMORY

❑ Shared Memory In this model a region of memory is shared by the


cooperating process. Process can then exchanged information by
reading and writing data in the shared region.

➢ Shared memory allows maximum speed and convenience of


communication.

➢ It is faster than message passing.

➢ A shared memory region resides in the address space of the process


creating the Shared memory segment.

➢ Two or more process can exchange information by reading and writing


data in shared region.
2. MESSAGE PASSING

➢ Message Passing : In this model communication task


place by means of message exchanged between the
cooperating process.

▪ Useful for exchanging smaller amount of data.

▪ It is easier to implement.

▪ Slower than shared memory.

▪ Useful in distributed environment.


Threads

➢ Threads, sometimes called lightweight processes are independently scheduled parts of a single program.

➢ We say that a task is multithreaded if it is composed of several independent sub-processes which do


work on common data, and if each of those pieces could run in parallel.
Shared Among Threads Unique For Each Thread

Code Section Thread Id

Data Section Register Set

OS Resources Stack

Open Files & Signals Program Counter


User Threads Kernel Thread

Multithreading in user process Multithreading in kernel process

Created without kernel intervention Kernel itself is multithreaded

Context switch is very fast Context switch is slow

If one thread is blocked, OS blocks entire process Individual thread can be blocked

Faster to create and manage Slower to create and manage


CPU Scheduling Criteria

•Arrival time: When a process enters the ready queue.

•Burst time: The amount of CPU time a process needs to complete its execution.

•Completion time: The time at which a process finishes executing.

•Turnaround time: The total time a process spends in the system (Completion time - Arrival time).

•Response time: The time it takes for a process to produce its first response.

•Waiting time: The time a process spends waiting in the ready queue (Turnaround time - Burst time).
Scheduling algorithms
❑ FCFS is a simple CPU scheduling algorithm used in operating systems. It operates on the principle
of First-In-First-Out (FIFO), where processes are executed in the order they arrive in the ready queue.

Process No. Arrival Burst time Completion Turn Waiting Response


time Time Around Time time
Time
P1 0 2 2 2 0 0

P2 1 2 4 3 1 1

P3 5 3 8 3 0 0

P4 6 4 12 6 2 2

Gantt Chart-
P1 P2 ////////////// P3 P4
0 2 4 5 8 12
❑ SJF is a CPU scheduling algorithm used in operating systems to manage processes efficiently.
It prioritizes processes based on their burst time, which is the time required for a process to
complete its execution.

Process Arrival Burst Completion Turn Waiting Response


No. time time Time Around Time time
Time
P1 1 3 6 5 2 2

P2 2 4 10 8 4 4

P3 1 2 3 2 0 0

P4 4 4 14 10 6 6

Gantt Chart-
////////////// P3 P1 P2 P4
0 1 3 6 10 14
Multiple processor scheduling

❑ Multiple processor scheduling, also known as multiprocessor scheduling, involves managing processes
across multiple CPUs to optimize system performance.

❑ This approach is crucial in modern computing systems where multiple processors are used to handle
large volumes of data efficiently.

Application -
➢ Multiprocessor systems are commonly used in applications requiring high processing power, such as
satellite operations, weather forecasting, and large-scale data processing

Advantage-

•Load Balancing
•Enhanced Responsiveness
•Efficient use of multicore processors
•Increased Throughput
•Improved Performance
Real Time Scheduling

❑ Real-time scheduling in operating systems is designed to manage tasks that have strict time constraints, ensuring
that critical tasks are executed within a specified deadline.

❑ This is particularly important in applications where predictability and determinism are crucial, such as in robotics,
flight control systems, and autonomous vehicles.

❑ Advantage

➢ Ensures tasks are completed within specified deadlines, crucial for safety-critical applications.

➢ Provides deterministic behavior, which is essential for systems requiring consistent performance.

➢ Optimizes CPU usage by prioritizing tasks based on urgency and deadlines

You might also like