0% found this document useful (0 votes)
37 views29 pages

Principles of Operating Systems Overview

Uploaded by

uvs5992
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)
37 views29 pages

Principles of Operating Systems Overview

Uploaded by

uvs5992
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

AIIT

Amity Institute of Information


Technology (AIIT)
BCA, I Semester number
CSIT 150 : Principles of Operating Systems
Dr. Akash Shah
ashah@[Link]
Room No. I1: 304
1
AIIT

Module 2

2
Process AIIT

• A process is a program in execution (active entity).


• Program = passive (set of instructions on disk).
• Process = program + execution state (values of
CPU registers, program counter, variables, open
files).
• Components of a process:
[Link] section – code
[Link] section – global variables
[Link] – dynamic memory
[Link] – function calls, local variables

3
Process AIIT

4
Process State AIIT

A process goes through different states during its lifetime. These states
represent what the process is currently doing. When you run a program
(which becomes a process), it goes through different phases before it
completion. These phases, or states, can vary depending on the operating
system

5
Process State AIIT

• New: The process is being created.


• Running: Instructions are being executed.
• Waiting: The process is waiting for some event to occur
(such as an I/O completion or reception of a signal).
• Ready: The process is waiting to be assigned to a
processor.
• Terminated: The process has finished execution.

6
Types of Schedulers AIIT

• Long-Term Scheduler: Decides how many processes should be


made to stay in the ready state. This decides the degree
of multiprogramming. Once a decision is taken it lasts for a long time
which also indicates that it runs infrequently. Hence it is called a
long-term scheduler.
• Short-Term Scheduler: 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 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.

7
Process Control Block AIIT

A Process Control Block (PCB) is a data structure used by the


operating system to manage information about a process. The
process control keeps track of many important pieces of
information needed to manage processes efficiently. The
diagram helps explain some of these key data items.

8
Process Control Block AIIT

• Process state: It stores the respective state of the process.


• Process number: Every process is assigned a unique id known as process
ID or PID which stores the process identifier.
• Program counter: Program Counter stores the counter, which contains the
address of the next instruction that is to be executed for the process.
• Register: Registers in the PCB, it is a data structure. When a processes is
running and it's time slice expires, the current value of process specific
registers would be stored in the PCB and the process would be swapped
out. When the process is scheduled to be run, the register values is read
from the PCB and written to the CPU registers. This is the main purpose of
the registers in the PCB.
• Memory limits: This field contains the information about memory
management system used by the operating system. This may include page
tables, segment tables, etc.
• List of Open files: This information includes the list of files opened for a
process.
9
Process Synchronization AIIT

Process Synchronization is a mechanism in operating


systems used to manage the execution of multiple
processes that access shared resources. Its main
purpose is to ensure data consistency, prevent race
conditions, and avoid deadlocks in a multi-process
environment. On the basis of synchronization,
processes are categorized as one of the following two
types:
• Independent Process: The execution of one process does
not affect the execution of other processes.
• Cooperative Process: A process that can affect or be
affected by other processes executing in the system.

10
Process Synchronization AIIT

Race Condition: A race condition is a


situation that may occur inside a critical
section. This happens when the result of
multiple process/thread execution in the
critical section differs according to the order
in which the threads execute.

11
Process Synchronization AIIT

The two primary type of process Synchronization in an Operating


System are:
• Competitive: Two or more processes are said to be in Competitive
Synchronization if and only if they compete for the accessibility of a
shared resource. Lack of Proper Synchronization among Competing
process may lead to either Inconsistency or Data loss.
• Cooperative: Two or more processes are said to be in Cooperative
Synchronization if and only if they get affected by each other i.e.
execution of one process affects the other process.
Lack of Proper Synchronization among Cooperating process may
lead to Deadlock.

12
Critical Section AIIT

A critical section is a code


segment that can be accessed
by only one process at a time.
The critical section contains
shared variables that need to
be synchronized to maintain
the consistency of data
variables. So the critical
section problem means
designing a way for
cooperative processes to
access shared resources
without creating data
inconsistencies.

13
Critical Section AIIT

The solution to the critical section problem must satisfy three


requirements:
• Mutual Exclusion: If a process is executing in its critical section,
then no other process is allowed to execute in the critical section.
• Progress: If no process is executing in the critical section and other
processes are waiting outside the critical section, then only those
processes that are not executing in their remainder section can
participate in deciding which will enter the critical section next and
the selection cannot be postponed indefinitely.
• Bounded Waiting: A bound must exist on the number of times that
other processes are allowed to enter their critical sections after a
process has made a request to enter its critical section and before
that request is granted.

14
Critical Section AIIT

Semaphore: Semaphores use a counter to control access, allowing


synchronization for multiple instances of a resource. Processes can
attempt to access one instance, and if it is not available, they can try
other instances. Unlike basic locks, which allow only one process to
access one instance of a resource. Semaphores can handle more
complex synchronization scenarios, involving multiple processes or
threads. It help prevent problems like race conditions by controlling
when and how processes access shared data.
The process of using Semaphores provides two operations:
• wait (P): The wait operation decrements the value of the semaphore
• signal (V): The signal operation increments the value of the
semaphore.

15
Critical Section AIIT

Types of Semaphore
• Binary Semaphore: This is also known as a mutex lock, as
they are locks that provide mutual exclusion. It can have only
two values - 0 and 1. Its value is initialized to 1. It is used to
implement the solution of critical section problems with
multiple processes and a single resource.
• Counting Semaphore: Counting semaphores can be used to
control access to a given resource consisting of a finite
number of instances. The semaphore is initialized to the
number of resources available. Its value can range over an
unrestricted domain.

16
Critical Section AIIT

Mutex: It stands for Mutual Exclusion Object. Mutex is mainly used to


provide mutual exclusion to a specific portion of the code so that the
process can execute and work with a particular section of the code at a
particular time. A mutex enforces strict ownership. Only the thread that
locks the mutex can unlock it. It is specifically used for locking a
resource to ensure that only one thread accesses it at a time. Due to
this strict ownership, a mutex is not only typically used for signaling
between threads, but it is used for mutual exclusion also to ensuring
that a resource is accessed by only one thread at a time.

17
Producer Consumer Problem AIIT
• Producer Process should not produce any data when the
shared buffer is full.
• Consumer Process should not consume any data when the
shared buffer is empty.
• The access to the shared buffer should be mutually exclusive
i.e at a time only one process should be able to access the
shared buffer and make changes to it.

18
AIIT

Main Issues
• Synchronization: Producer and Consumer should
not access the buffer at the same time → prevents
race conditions.
• Mutual Exclusion: Only one thread should modify
the buffer at a time.
• Avoid Deadlock: Both should not end up waiting
forever.
• Avoid Starvation: Each process should get a fair
chance.

19
Producer Consumer ProblemAIIT

20
Process Scheduling AIIT

Process scheduling is the activity of the process manager that


handles the removal of the running process from the CPU and
the selection of another process based on a particular strategy.
Throughout its lifetime, a process moves between various
scheduling queues, such as the ready queue, waiting queue or
devices queue.
Types of Process Scheduling:
• Non-Preemptive: In this case, a process's resource cannot be
taken before the process has finished running. When a running
process finishes and transitions to a waiting state, resources are
switched.
• Preemptive: In this case, the OS can switch a process from running
state to ready state. This switching happens because the CPU may
give other processes priority and substitute the currently active
process for the higher priority process.
21
Process Scheduling AIIT

22
Inter Process Communication AIIT

(IPC)
Processes need to communicate with each other in many
situations. Inter-Process Communication or IPC is a
mechanism that allows processes to communicate.
• It helps processes synchronize their activities, share
information and avoid conflicts while accessing shared
resources.
• There are two method of IPC, shared memory and message
passing. An operating system can implement both methods of
communication.

23
Inter Process Communication AIIT

(IPC)

24
Inter Process Communication AIIT

(IPC)
Shared Memory
• In the shared memory model, a common memory space is
allocated by the kernel.
• Process A writes data into the shared memory region (Step
1).
• Process B can then directly read this data from the same
shared memory region (Step 2).
• Since both processes access the same memory segment, this
method is fast but requires synchronization mechanisms (like
semaphores) to avoid conflicts when multiple processes
read/write simultaneously.

25
Inter Process Communication AIIT

(IPC)
Memory Passing
• In the message passing model, processes exchange
information by sending and receiving messages through the
kernel.
• Process A sends a message to the kernel (Step 1).
• The kernel then delivers the message to Process B (Step 2).
• Here, processes do not share memory directly. Instead,
communication happens via system calls (send(), recv(), or
similar).
• This method is simpler and safer than shared memory
because there’s no risk of overwriting shared data, but it
incurs more overhead due to kernel involvement.

26
Thread AIIT

• A thread is the smallest unit of CPU execution.


• Sometimes called a lightweight process.
• Each thread has:
o Program counter (PC) → next instruction
o Registers → temporary data
o Stack → function calls, local variables

27
Types of Thread AIIT

• User-Level Threads (ULTs):


o Managed by user libraries (not OS).
o Fast to create & switch.
o But if one thread blocks, the entire process blocks.
• Kernel-Level Threads (KLTs):
o Managed directly by the OS.
o Better scheduling (true parallelism on multiprocessors).
o Slower context switching (needs OS involvement).

28
Multithreading AIIT

• Many-to-One Model
o Many user threads mapped to one kernel thread.
o Simple but no true parallelism; if one blocks, all block.
• One-to-One Model
o Each user thread maps to one kernel thread.
o High concurrency, but expensive (requires more kernel resources).
• Many-to-Many Model
o Many user threads mapped to smaller or equal number of kernel
threads.
o Combines efficiency & parallelism.

29

You might also like