Nehu_OSYfinal
Nehu_OSYfinal
MICRO PROJECT
Academic year: 2024-25
TITLE OF PROJECT
Semaphores
1
Teacher Evaluation Sheet
Name of Student: Jamdhade Neha Anil
Enrolment No: 2200790153
Name of Program: Computer Technology Semester: -V
Course Title: Operating System (OSY) Code: -22516
Title of the Micro Project: Semaphores
(A) Process and Product Assessment (Convert above total marks out of 6 marks)
1 Relevance to the Course
Literature Survey /
2
Information Collection
Completion of the Target as per
3
project proposal
Analysis of data and
4
representation
5 Quality of Prototype / Model
6 Report Preparation
(B) Individual Presentation / Viva (Convert above total marks out of 4 marks)
8 Presentation
9 Viva
Micro – Project Evaluation Sheet:
Process Assessment Product Assessment
Part Part
A – project Project B – Project Individual Total
Proposal Methodology Report / Working Presentation / Marks
Name of Student (2 marks (2 marks) Model (2 marks) Viva (4 marks) 10
2
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
CERTIFICATE
This is to certify that Jamdhade Neha Anil of 5th Semester of Diploma in Computer Technology of
Institute, SNJB’s SHRI HIRALAL. HASTIMAL (JAIN. BROTHERS, Jalgaon) POLYTECHNIC,
Chandwad (Code: 0079) has completed the Micro-Project satisfactorily in Subject Operating System
(22516) for the academic year 2024-2025 as prescribed in the curriculum.
Place: Chandwad
Date: 18 /11/2024
Seal of
Institute
3
Index
5
1 Brief Introduction
5
2 Course Outcomes Addressed
3 5
Proposed Methodology
5
4 Action Plan
6
5 Resources Required
Part B
7
1 Brief Description
7
2 Aim of Micro Project
7
3 Course Outcome Integrated
7
4 Actual Procedure Followed
8
5 Actual Resource Used
8
6 Introduction
20
7 Skill Developed
21
8 Applications of Microproject
4
PART A-Plan
3. Proposed Methodology: -
1. Focused on the selection of an appropriate topic for the micro-project.
2. Select the topic i.e. To Prepare a report on semaphores process synchronization.
3. Brief study on our topic.
4. Gather all information based on the topic of the micro project.
5. Analysis and study of our topic in detail.
6. Following all the above methodologies we successfully completed our microproject.
4. Action Plan: -
Sr Planned Start Date Planned Finish Date
Details of activity
no.
1. Finalization of topic 25-07-2024 01-08-2024
5
5. Resources Required: -
Sr. Name of Resource/Material Specification Quantity Remarks
No
1. Computer (Desktop/Laptop) i5, RAM 16GB 1 Available
2. Microsoft office word 2010 1 Available
3. Books - - -
4. Websites ChatGPT 1 Available
5. Software Word, Ubuntu Available
1
6
PART B-Plan
Title of micro-project:Semaphores
1. Brief Description: -
In this project we are going to get all information about semaphores in process in process
synchronization. Semaphore was proposed by Dijkstra in 1965 which is a very significant technique
to manage concurrent processes by using a simple integer value, which is known as a semaphore. A
semaphore is simply an integer variable that is shared between threads. This variable is used to solve
the critical section problem and to achieve process synchronization in the multiprocessing
environment. An Operating System is basically a system program that controls the execution of
application programs and acts as an interface between applications and the computer hardware. It
manages the computer system resources to be used in an efficient manner. This course enables to learn
internal functioning of operating system and will help in identifying appropriate Operating System
for given applications/task. This course is also a prerequisite for the group of courses included in
'Cloud Infrastructure Maintenance' Elective group.
7
6. Introduction: -
1.Binary Semaphore:
This is also known as mutex lock. 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.
2.Counting Semaphore:
Its value can range over an unrestricted domain. It is used to control access to a resource that has multiple
instances.
two operations that can be used to access and change the value of the semaphore variable.
8
Some point regarding P and V operation:
1. P operation is also called wait, sleep, or down operation, and V operation is also called signal, wake-
up, or up operation.
2. Both operations are atomic and semaphore(s) is always initialized to one. Here atomic means that
variable on which read, modify and update happens at the same time/moment with no pre-emption i.e.
in-between read, modify and update no other operation is performed that may change the variable.
3. A critical section is surrounded by both operations to implement process synchronization. See the
below image. The critical section of Process P is in between P and V operation.
9
Now, let us see how it implements mutual exclusion. Let there be two processes P1 and P2 and a
semaphore s is initialized as 1. Now if suppose P1 enters in its critical section then the value of semaphore
s becomes 0. Now if P2 wants to enter its critical section then it will wait until s > 0, this can only happen
when P1 finishes its critical section and calls V operation on semaphore s.
This way mutual exclusion is achieved. Look at the below image for details which is Binary semaphore.
10
IMPLEMENTATION: BINARY SEMAPHORES (C++)
struct semaphore {
enum value(0, 1);
} P(semaphore s)
{
if (s.value == 1) {
11
s.value = 0;
}
else {
// add the process to the waiting queue
q.push(P) sleep();
}
}
V(Semaphore s)
{
if (s.q is empty) {
s.value = 1;
}
else {
12
The main problem with semaphores is that they require busy waiting, If a process is in the critical
section, then other processes trying to enter the critical section will be waiting until the critical section
is not occupied by any process. Whenever any process waits then it continuously checks for semaphore
value (look at this line while (s==0); in P operation) and waste CPU cycle.
There is also a chance of “spinlock” as the processes keep on spins while waiting for the lock. In order
to avoid this another implementation is provided below.
IMPLEMENTATION: COUNTING SEMAPHORE (CPP)
struct Semaphore {
int value;
} P(Semaphore s)
{
s.value = s.value - 1;
if (s.value < 0) {
V(Semaphore s)
{
s.value = s.value + 1;
if (s.value <= 0) {
wakeup(p);
}
13
else
return;
}
In this implementation whenever the process waits it is added to a waiting queue of processes associated
with that semaphore. This is done through system call block() on that process. When a process is
completed it calls the signal function and one process in the queue is resumed. It uses wakeup() system
call.
• ADVANTAGES OF SEMAPHORES
• DISADVANTAGES OF SEMAPHORES:
1. Semaphores are complicated so the wait and signal operations must be implemented in the correct
order to prevent deadlocks.
2. Semaphores are impractical for last scale use as their use leads to loss of modularity. This happens
because the wait and signal operations prevent the creation of a structured layout for the system.
3. Semaphores may lead to a priority inversion where low priority processes may access critical
section first and high priority processes later.
When the Dutch computer scientist named Edsger Dijkstra and his team were designing an OS for the
Electrologica X8, they devised the semaphore concept. And this technology happened to be known as
THE multiprogramming system over time. Dijkstra presented a solution to the problem of squandering
wake-up signals, which requires storing all of the wake-up calls. According to Dijkstra, instead of
providing the wake-up calls to the customer directly, the producer can store them in a variable.
Any of the customers can read it at any time they choose. Semaphore is a variable that keeps all of the
wake-up calls that are sent from the producer to the consumer. In kernel mode, it is a variable on which
modify, read, and update occur automatically.
Because race conditions can always occur when multiple processes try accessing the variable at the same
time, a semaphore cannot be implemented in user mode. It is always dependent on the operating system for
implementation.
14
7. Skill Developed: -
1. Studying of the semaphores process synchronization.
2. Learned semaphore types.
3. Learned implementation of semaphores process synchronization.
8. Applications of Microproject: -
1.Producer-Consumer Problem:
Model a system where one process (producer) generates data and another (consumer) consumes it.
Semaphores can ensure that the consumer doesn't access data before it's produced and the producer
doesn't overwrite data until it's consumed.
2. Readers-Writers Problem:
Simulate a shared resource (e.g., a file) accessed by multiple processes. Semaphores can control access
to the resource, allowing multiple readers but only one writer at a time.
15
16
17