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

Nehu_OSYfinal

The document outlines a micro-project titled 'Semaphores' conducted by student Jamdhade Neha Anil as part of the Computer Technology program at SNJB’s Shri Hiralal Hastimal Polytechnic. It details the project's objectives, methodology, and evaluation criteria, emphasizing the significance of semaphores in process synchronization within operating systems. The project aims to explore semaphore operations and their applications in solving synchronization problems while addressing course outcomes related to operating system tools and process management.

Uploaded by

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

Nehu_OSYfinal

The document outlines a micro-project titled 'Semaphores' conducted by student Jamdhade Neha Anil as part of the Computer Technology program at SNJB’s Shri Hiralal Hastimal Polytechnic. It details the project's objectives, methodology, and evaluation criteria, emphasizing the significance of semaphores in process synchronization within operating systems. The project aims to explore semaphore operations and their applications in solving synchronization problems while addressing course outcomes related to operating system tools and process management.

Uploaded by

Neha Jamdhade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

SNJB’s SHRI HIRALAL HASTIMAL (JAIN


BROTHERS, Jalgaon) POLYTECHNIC, Chandwad-423101
(Nashik)

MICRO PROJECT
Academic year: 2024-25

TITLE OF PROJECT

Semaphores

Program: Computer Technology Program Code: CM


Course: Operating System Course code: 22516

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

Course Outcomes Addressed: -


a) CO- a Install Linux operating system and configure it.
b) CO-b Use operating system tools to perform various functions.
c) CO-c Execute process commands for performing process management operations.
d) CO-d Apply scheduling algorithms to calculate turnaround time and average waiting time.
e) CO-e Calculate efficiency of different memory management techniques.
f) CO-f Apply file management techniques.

Evaluation as per Suggested Rubric for Assessment of Micro-Project:


Sr.
Characteristic to be Poor (Marks Average Good Excellent
No.
assessed 1-3) (Marks 4-5) (Marks 6 - 8) (Marks 9-10)

(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

Jamdhade Neha Anil


Comments / Suggestions about team work / leadership / inter – personal communication (if any) Any Other
Comment

Name and designation of the faculty Member: Ms. S. S. Shinde Signature

2
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Sr. No. Name of Student Roll No Enrollment No Seat No


1. Jamdhade Neha Anil 29 2200790153 390753

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

Course Teacher Head of the Department Principal


(Ms. S. S. Shinde) ( Mr. P. R. Sali) (Dr. V. A. Wankhede)

Seal of
Institute

3
Index

SR_NO. CONTENT PAGE NO.


Part A

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

Title of micro-project: - Semaphores

1. Brief Introduction of the Micro-Project: -


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.

2. Course Outcomes Addressed: -


a) CO- a Install Linux operating system and configure it.
b) CO-b Use operating system tools to perform various functions.
c) CO-c Execute process commands for performing process management operations.
d) CO-d Apply scheduling algorithms to calculate turnaround time and average waiting time.
e) CO-e Calculate efficiency of different memory management techniques.
f) CO-f Apply file management techniques.

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

2. Preparation of Abstract 01-08-2024 08-08-2024

3. Collection of data 20-08-2024 25-08-2024

4. Submission of Micro Project 18-11-2024 18-11-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.

2. Aims of Micro Project: -


1.To study the fundamental principles of semaphores and their role in operating systems.
2.To implement semaphore operations (P and V) in a simulated environment.
3.To analyze and solve classical synchronization problems (producer-consumer, reader-writer,
dining philosophers) using semaphores.
4.To evaluate the effectiveness of semaphores in preventing race conditions and deadlocks.

3. Course Outcomes Archived: -


a) CO-a Install Linux operating system and configure it.
b) CO-c Execute process commands for performing process management operations.

4. Actual Methodology/Procedure Followed: -


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.

5. Actual Resources Used: -


Sr. No Name of Resource/Material Specification Quantity Remarks
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 1 Available

7
6. Introduction: -

SEMAPHORES 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.
Semaphores are two types:

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);

// q contains all Process Control Blocks (PCBs)


// corresponding to processes got blocked
// while performing down operation.
Queue<process> q;

} 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 {

// select a process from waiting queue


Process p = q.front();
// remove the process from waiting as it has been
// sent for CS
q.pop();
wakeup(p);
}
}
The description above is for binary semaphore which can take only two values 0 and 1 and ensure mutual
exclusion. There is one other type of semaphore called counting semaphore which can take values greater than
one.
Now suppose there is a resource whose number of instances is 4. Now we initialize S = 4 and the rest is the
same as for binary semaphore. Whenever the process wants that resource it calls P or waits for function and
when it is done it calls V or signal function. If the value of S becomes zero then a process has to wait until S
becomes positive. For example, Suppose there are 4 processes P1, P2, P3, P4, and they all call wait operation
on S(initialized with 4). If another process P5 wants the resource then it should wait until one of the four
processes calls the signal function and the value of semaphore becomes positive.
Limitations :

1. One of the biggest limitations of semaphore is priority inversion.


2. Deadlock, suppose a process is trying to wake up another process which is not in a sleep state.
Therefore, a deadlock may block indefinitely.
3. The operating system has to keep track of all calls to wait and to signal the semaphore.

Problem in this implementation of semaphore :

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;

// q contains all Process Control Blocks(PCBs)


// corresponding to processes got blocked
// while performing down operation.
Queue<process> q;

} P(Semaphore s)
{
s.value = s.value - 1;
if (s.value < 0) {

// add process to queue


// here p is a process which is currently executing
q.push(p);
block();
}
else
return;
}

V(Semaphore s)
{
s.value = s.value + 1;
if (s.value <= 0) {

// remove process p from queue


Process p = q.pop();

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

Some of the advantages of semaphores are as follows −


1. Semaphores allow only one process into the critical section. They follow the mutual exclusion
principle strictly and are much more efficient than some other methods of synchronization.
2. There is no resource wastage because of busy waiting in semaphores as processor time is not
wasted unnecessarily to check if a condition is fulfilled to allow a process to access the critical
section.
3. Semaphores are implemented in the machine independent code of the microkernel. So they are
machine independent.

• 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.

HISTORY OF SEMAPHORES IN OPERATING SYSTEMS

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

You might also like