Students Copy Operating System I CTE 243
Students Copy Operating System I CTE 243
OPERATING SYSTEMS I
General Objectives:
On completion of this course the student should be able to:
1. Know the concepts of an operating system
2. Know the classification and different types of Operating System
3. Know the functions, characteristics, and components of Operating System
4. Know services, properties, and structure of an Operating System
5. Understand the general concept of system programming
6. Understand the use of utilities and libraries
7. Understand Input / Output devices handlers
1
process management, disk management, I/O management, peripherals
management, etc.
Operating system (OS) is a program that manages a computer’s resources, especially
the allocation of those resources among other programs. Typical resources include
the central processing unit (CPU), computer memory, file storage, input/output (I/O)
devices, and network connections.
An Operating System is software that communicates with the hardware and allows
other programs to run. It is comprised of system software, or the fundamental files
the computer needs to boot up and function.
Common desktop operating systems include Windows, OS X, and Linux. Mobile
devices, such as tablets and smartphones also include operating systems that
provide a GUI and can run applications. Common mobile OSes include Android, iOS,
and Windows Phone.
3
CLASSIFICATION AND DIFFERENT TYPES OF OPERATING
SYSTEMS
OPEN AND CLOSED SOURCE OPERATING SYSTEMS
Open-Source Operating System
An open-source operating system allows the public to make changes to the source
code of the software. This permission or access is granted by the author of the
operating system. Such operating system software are usually free online. Such
companies are Unix, Linux and an example of such operating systems are Ubuntu.
Closed-Source Operating System
A Closed Source Operating System does not authorize public users to make changes
to the source code of the software. The production company does the modification
themselves. Examples of Closed-source Operating Systems are Microsoft Windows,
Mac OS, Android, IOS.
2. UNIX: Developed in 1970 in the Bell Lab research centre UNIX became a
multitasking and multiuser operating system, reaching numerous platforms
for use. It was developed by Ken Thompson, Dennis Ritchie, and a few others
and later AT&T licensed UNIX to the development of many variants of Unix.
Advantages of UNIX
The OS is available on a wide variety of machines that are the most truly
portable operating system.
It has a Very efficient virtual memory system, which allows many programs to
run simultaneously with a modest amount of physical memory and time.
The OS was primarily built to serve the complete multitasking purpose
without crashing of data, and it served well along with the protected memory.
Has a high-level authentication system along with a fully secured
environment.
Disadvantages of UNIX
4
This OS was primarily designed for programmers and techies and not for
personal and casual use.
It is a command-driven OS with commands being supplied by the shell kernel
and often has cryptic names which normal users find difficult to keep up with.
To work comfortably with the UNIX system, one needs to understand the main
design features and how to command and interact with the OS.
3. Linux: Primarily derived from the concept of Unix, Linux became the most-
prominent free and open-source OS available to everyone in the world. It is
built around the Linux kernel and served for both desktop and server use. The
top Linux OS are Ubuntu, Fedora, OpenSUSE, RedHat, and many more.
Advantages of LINUX
The OS is open-source and available free of cost to every computer user.
There are large repositories from which anyone can freely download high-
quality software for almost any task.
Linux provides high performance for a longer time and does not require a
periodic reboot to maintain the system.
It is one of the most secure OS and does not permit any unwanted malware
and virus into the system.
It is designed to multitask and can perform multiple processes at the same
time, without hampering the performance of the OS.
The OS is highly compatible and flexible to run on all modern PCs and
networks.
Disadvantages of LINUX
It is not as user-friendly as Windows and users need to struggle for a few days
before adapting to the behaviour of OS.
It is not meant for gamers since it does not support any high graphics game.
Since there are no standard editions available for Linux, it comes with many
versions, confusing the users about what to adapt and what not.
5
India. It has an enhanced Desktop Environment integrated with multiple
Indian language support and other software.
Advantages of BOSS
It is easily available and free to install and use.
It is a very stable OS and provides free access to many software.
It supports multiple Indian languages, so user-friendly at least for Indian
society.
Disadvantages of BOSS
Since it is Linux OS, it does not support Windows programs and shares the
same disadvantages as other Linux-based OS.
6
Advantages of Time-Sharing OS:
Each task gets an equal opportunity.
Fewer chances of duplication of
software.
CPU idle time can be reduced
7
Examples of Real-Time Operating Systems are: Scientific experiments, medical
imaging systems, industrial control systems, weapon systems, robots, air traffic
control systems, etc.
8
each other using a shared communication network. Independent systems possess
their own memory unit and CPU. These are referred to as loosely coupled systems or
distributed systems. These system’s processors differ in size and function. The major
benefit of working with these types of the operating system is that it is always
possible that one user can access the files or software which are not actually present
on his system but some other system connected within this network i.e., remote
access is enabled within the devices connected in that network.
Advantages of Distributed Operating
System:
Failure of one will not affect the other
network communication, as all systems
are independent from each other.
Electronic mail increases the data
exchange speed.
Since resources are being shared,
computation is highly fast and durable.
Load on host computer reduces.
These systems are easily scalable as
many systems can be easily added to
the network.
Delay in data processing reduces.
Disadvantages of Distributed Operating System:
Failure of the main network will stop the entire communication.
To establish distributed systems the language which is used are not well
defined yet.
These types of systems are not readily available as they are very expensive.
Not only that the underlying software is highly complex and not understood
well yet.
Examples of Distributed Operating System are- LOCUS, etc.
COMPUTING ENVIRONMENTS
Types of Computing Environments
The different types of Computing Environments are −
Personal Computing Environment: In the personal computing environment,
there is a single computer system. All the system processes are available on the
computer and executed there. The different devices that constitute a personal
computing environment are laptops, mobiles, printers, computer systems, scanners
etc.
Time-Sharing Computing Environment: The time-sharing computing
environment allows multiple users to share the system simultaneously. Each user is
provided a time slice and the processor switches rapidly among the users according
to it.
9
Client-Server Computing Environment: In client server computing, the client
requests a resource and the server provides that resource. A server may serve
multiple clients at the same time while a client is in contact with only one server.
Both the client and server usually communicate via a computer network but
sometimes they may reside in the same system.
Distributed Computing Environment: A distributed computing environment
contains multiple nodes that are physically separate but linked together using the
network. All the nodes in this system communicate with each other and handle
processes in tandem. Each of these nodes contains a small part of the distributed
operating system software.
Cloud Computing Environment: The computing is moved away from individual
computer systems to a cloud of computers in cloud computing environment. The
cloud users only see the service being provided and not the internal details of how
the service is provided.
Cluster Computing Environment: The clustered computing environment is
similar to parallel computing environment as they both have multiple CPUs.
However, a major difference is that clustered systems are created by two or more
individual computer systems merged together which then work parallel to each
other.
CHAPTER THREE
FUNCTIONS, CHARACTERISTICS, AND COMPONENTS OF OPERATING
SYSTEMS
An operating system manages resources, and these resources are often shared in
one way or another among the various programs that want to use them: multiple
programs executing concurrently share the use of main memory; they take turns
using the CPU; and they compete for an opportunity to use input and output devices.
10
scheduling and such as resource allocation. It also manages the memory allocated to
processes and shutting them down when needed.
Functions of process management by the Operating System
The following are functions of process management:
Process creation and deletion.
Suspension and resumption.
Synchronization process.
Communication process.
11
Keep track of the I/O devices, I/O channels, etc. This module is typically called
I/O traffic controller.
Decide what is an efficient way to allocate the I/O resource. If it is to be shared,
then decide who gets it, how much of it is to be allocated, and for how long.
This is called I/O scheduling.
Allocate the I/O device and initiate the I/O operation.
Reclaim device when its use is through. In most cases I/O terminates
automatically.
3. Long term storage: Many users and applications required means for storing
information for extended periods, since they are in need for data, program and
routine sharing which are stored in Ram or secondary storage. The things to be
considered are:
Assessment to the data/ easy programs
Security from any interference
Protection from any system breakdown
4. Small size: Operating system should be in a small size to reduce the use of
memory and storage. The operating system storage cannot be used to run any
user programs. The reduction of memory and storage allows the user to use
the memory to run their programs.
13
Provides synchronization mechanisms to control concurrent access to shared
data to keep shared data consistent.
Allocate/de-allocate resources properly to prevent or avoid deadlock situation.
2. I/O Device Management: Following are the tasks of I/O Device Management
component:
Hide the details of H/W devices
Manage main memory for the devices using cache, buffer, and spooling
Maintain and provide custom drivers for each device.
14
programming environment to the users. Command Interpreter System
executes a user command by calling one or more number of underlying system
programs or system calls.
15
The OS defines a job which has predefined sequence of commands,
programs and data as a single unit.
The OS keeps a number a job in memory and executes them without any
manual information.
Jobs are processed in the order of submission, i.e., first come first served
fashion.
When a job completes its execution, its memory is released and the
output for the job gets copied into an output spool for later printing or
processing.
Advantages
Batch processing takes much of the work of the operator to the
computer.
Increased performance as a new job get started as soon as the previous
job is finished, without any manual intervention.
Disadvantages
Difficult to debug program.
A job could enter an infinite loop.
Due to lack of protection scheme, one batch job can affect pending jobs.
Disadvantages
CPU scheduling is required.
To accommodate many jobs in memory, memory management is
required.
18
Operating system structure can be thought of as the strategy for connecting and
incorporating various operating system components within the kernel. Operating
systems are implemented using many types of structures:
19
The core of an operating system for
computers is called the kernel (OS).
All other System components are
provided with fundamental services
by the kernel. The operating system
and the hardware use it as their main
interface. When an operating system
is built into a single piece of
hardware, such as a keyboard or
mouse, the kernel can directly access
all of its resources.
EXOKERNEL
An operating system called Exokernel was created at MIT with the goal of offering
application-level management of hardware resources. The exokernel architecture's
goal is to enable application-specific customization by separating resource
management from protection. Exokernel size tends to be minimal due to its limited
operability.
Exokernel operating systems have a number of features, including:
Enhanced application control support.
Splits management and security apart.
21
A secure transfer of abstractions is made to an unreliable library operating
system.
Brings up a low-level interface.
Operating systems for libraries provide compatibility and portability.
Advantages of Exokernel Structure:
Application performance is enhanced by it.
Accurate resource allocation and revocation enable more effective
utilisation of hardware resources.
New operating systems can be tested and developed more easily.
Every user-space program is permitted to utilise its own customised
memory management.
Disadvantages of Exokernel Structure:
A decline in consistency
Exokernel interfaces have a complex architecture.
PROCESS MANAGEMENT
Process management includes various roles and responsibilities such as allocating
system resources, memory management, manage input/output devices for running
system processes and scheduling the execution of processes in such a way that
maximizes throughput and minimum response times.
Process management can help organizations improve their operational efficiency,
reduce costs, increase customer satisfaction, and maintain compliance with
22
regulatory requirements. It involves analysing the performance of existing processes,
identifying bottlenecks, and making changes to optimize the process flow.
Some of the systems call in this category are as follows.
Create a child’s process identical to the parents.
Terminate a process
Wait for a child process to terminate
Change the priority of the process
Block the process
Ready the process
Dispatch a process
Suspend a process
Resume a process
Delay a process
Fork a process
Explanation of Process
Text Section: A Process, sometimes known as the Text
Section, also includes the current activity represented
by the value of the Program Counter.
Stack: The stack contains temporary data, such as
function parameters, returns addresses, and local
variables.
Data Section: Contains the global variable.
Heap Section: Dynamically memory allocated to
process during its run time.
Key Components of Process Management
Below are some key components of process management.
Process mapping: Creating visual representations of processes to understand
how tasks flow, identify dependencies, and uncover improvement
opportunities.
Process analysis: Evaluating processes to identify bottlenecks, inefficiencies,
and areas for improvement.
Process redesign: Making changes to existing processes or creating new
ones to optimize workflows and enhance performance.
Process implementation: Introducing the redesigned processes into the
organization and ensuring proper execution.
Process monitoring and control: Tracking process performance, measuring
key metrics, and implementing control mechanisms to maintain efficiency and
effectiveness.
Characteristics of a Process
A process has the following attributes.
Process Id: A unique identifier assigned by the operating system.
23
Process State: Can be ready, running, etc.
CPU registers: Like the Program Counter
(CPU registers must be saved and restored
when a process is swapped in and out of the
CPU)
Accounts information: Amount of CPU used
for process execution, time limits, execution
ID, etc
I/O status information: For example, devices allocated to the process, open
files, etc
CPU scheduling information: For example, Priority (Different processes may
have different priorities, for example, a shorter process assigned high priority
in the shortest job first scheduling)
All of the above attributes of a process are also known as the context of the
process. Every process has its own process control block (PCB), i.e. each process will
have a unique PCB. All of the above attributes are part of the PCB.
States of Process
A process is in one of the following states:
New: Newly Created Process (or) being-created process.
Ready: After the creation process moves to the Ready state, i.e., the process
is ready for execution.
Run: Currently running process in CPU (only one process at a time can be
under execution in a single processor)
Wait (or Block): When a process requests I/O access.
Complete (or terminated): The process completed its execution.
Suspended Ready: When the ready queue becomes full, some processes are
moved to a suspended ready state
Suspended Block: When the waiting queue becomes full.
24
In order for a process execution to be continued from the same point at a later time,
context switching is a mechanism to store and restore the state or context of a CPU
in the Process Control block. A context switcher makes it possible for multiple
processes to share a single CPU using this method. A multitasking operating
system must include context switching among its features.
The state of the currently running process is saved into the process control block
when the scheduler switches the CPU from executing one process to another. The
state used to set the computer, registers, etc. for the process that will run next is
then loaded from its own PCB. After that, the second can start processing.
In order for a process execution to be
continued from the same point at a later
time, context switching is a mechanism to
store and restore the state or context of a
CPU in the Process Control block. A context
switcher makes it possible for multiple
processes to share a single CPU using this
method.
Disadvantages-
1. Overhead
2. Complexity
3. Scalability
4. Security
26
Pre-emptive Scheduling: Pre-emptive scheduling is used when a process
switches from running state to ready state or from the waiting state to the
ready state.
Non-Pre-emptive Scheduling: Non-Pre-emptive scheduling is used when a
process terminates, or when a process switches from running state to waiting
state.
27
It is associated with each task as a unit of time to complete.
It may cause starvation if shorter processes keep coming. This problem can
be solved using the concept of ageing.
Advantages of Shortest Job first:
As SJF reduces the average waiting time thus, it is better than the first come
first serve scheduling algorithm.
SJF is generally used for long term scheduling
Disadvantages of SJF:
One of the demerits SJF has is starvation.
Many times, it becomes complicated to predict the length of the upcoming CPU
request
3. Longest Job First (LJF):
Longest Job First (LJF) scheduling process is just opposite of shortest job first (SJF),
as the name suggests this algorithm is based upon the fact that the process with the
largest burst time is processed first. Longest Job First is non-preemptive in nature.
Characteristics of LJF:
Among all the processes waiting in a waiting queue, CPU is always assigned to
the process having largest burst time.
If two processes have the same burst time then the tie is broken using FCFS i.e.
the process that arrived first is processed first.
LJF CPU Scheduling can be of both preemptive and non-preemptive types.
Advantages of LJF:
No other task can schedule until the longest job or process executes
completely.
All the jobs or processes finish at the same time approximately.
Disadvantages of LJF:
Generally, the LJF algorithm gives a very high average waiting
time and average turn-around time for a given set of processes.
This may lead to convoy effect.
4. Priority Scheduling:
Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method of CPU
scheduling algorithm that works based on the priority of a process. In this
algorithm, the editor sets the functions to be as important, meaning that the most
important process must be done first. In the case of any conflict, that is, where there
is more than one process with equal value, then the most important CPU planning
algorithm works on the basis of the FCFS (First Come First Serve) algorithm.
Characteristics of Priority Scheduling:
Schedules tasks based on priority.
When the higher priority work arrives and a task with less priority is executing,
the higher priority proess will takes the place of the less priority proess and
28
The later is suspended until the execution is complete.
Lower is the number assigned, higher is the priority level of a process.
30
There is a reduction in waiting time for longer jobs and also it encourages
shorter jobs.
Disadvantages of HRRN:
The implementation of HRRN scheduling is not possible as it is not possible to
know the burst time of every job in advance.
In this scheduling, there may occur an overload on the CPU.
APPLICATION PROGRAMMING
Similarly, Application Programming is the act of building application programs for
specific set of purposes such as creation of documents, spreadsheets, reading and
recording music files, etc.
DIFFERENCE BETWEEN SYSTEM PROGRAMS AND APPLICATION PROGRAMS
System programs are programs that typically aids in the management of the
computer system. Some systems programs aid external hardware devices to run
properly (device drivers), some help in system security management (antiviruses,
disk scanners, firewalls, etc), some aid in other functions of management, which is
generally managed by the operating system.
On the other hand, application programs help the users to perform specific tasks
such as recording, printing, etc.
32
Utility Software is a type of software which is used to analyse and maintain
a computer. This software is focused on how OS works on that basis it performs tasks
to enable the smooth functioning of the computer. This software may come with OS
like windows defender and disk clean-ups tools. Antivirus, backup software, file
manager, and disk compression tool all are utility software.
Types of Utility Software
Some of the most common types of utility software include –
Antivirus software
Disk cleaners
Backup and recovery software
System optimizers
Disk defragmenters File compression software
Disk encryption software
Operating System - I/O Softwares
I/O software is often organized in the following layers −
User Level Libraries − This provides simple interface to the user program to
perform input and output. For example, stdio is a library provided by C and C+
+ programming languages.
Kernel Level Modules − This provides device driver to interact with the
device controller and device independent I/O modules used by the device
drivers.
Hardware − This layer includes actual hardware and hardware controller
which interact with the device drivers and makes hardware alive.
A key concept in the design of I/O software is that it should be device independent
where it should be possible to write programs that can access any I/O device without
having to specify the device in advance.
Device Drivers
Device drivers are software modules that can be plugged into an OS to handle a
particular device. Operating System takes help from device drivers to handle all I/O
devices. Device drivers encapsulate device-dependent code and implement a
standard interface in such a way that code contains device-specific register
reads/writes.
A device driver performs the
following jobs −
To accept request from the
device independent software
above to it.
Interact with the device
controller to take and give I/O
and perform required error
handling
33
Making sure that the request is executed successfully
How a device driver handles a request is as follows: Suppose a request comes to
read a block N. If the driver is idle at the time a request arrives, it starts carrying out
the request immediately. Otherwise, if the driver is already busy with some other
request, it places the new request in the queue of pending requests.
Interrupt handlers
An interrupt handler, also known as an interrupt service routine or ISR, is a piece of
software or more specifically a call-back function in an operating system or more
specifically in a device driver, whose execution is triggered by the reception of an
interrupt.
When the interrupt happens, the interrupt procedure does whatever it has to in order
to handle the interrupt, updates data structures and wakes up process that was
waiting for an interrupt to happen.
Device-Independent I/O Software
The basic function of the device-independent software is to perform the I/O functions
that are common to all devices and to provide a uniform interface to the user-level
software. Though it is difficult to write completely device independent software but
we can write some modules which are common among all the devices. Following is a
list of functions of device-independent I/O Software −
Uniform interfacing for device drivers
Device naming - Mnemonic names mapped to Major and Minor device numbers
Device protection
Providing a device-independent block size
Buffering because data coming off a device cannot be stored in final
destination.
Storage allocation on block devices
Allocation and releasing dedicated devices
Error Reporting
34
Scheduling − Kernel schedules a set of I/O requests to determine a good
order in which to execute them. When an application issues a blocking I/O
system call, the request is placed on the queue for that device.
Buffering − Kernel I/O Subsystem maintains a memory area known
as buffer that stores data while they are transferred between two devices or
between a device with an application operation. Buffering is done to cope with
a speed mismatch between the producer and consumer of a data stream or to
adapt between devices that have different data transfer sizes.
Caching − Kernel maintains cache memory which is region of fast memory
that holds copies of data. Access to the cached copy is more efficient than
access to the original.
Spooling and Device Reservation − A spool is a buffer that holds output for
a device, such as a printer, that cannot accept interleaved data streams. The
spooling system copies the queued spool files to the printer one at a time.
Error Handling − An operating system that uses protected memory can guard
against many kinds of hardware and application errors.
INPUT/OUTPUT
Operating System - I/O Hardware
An I/O system is required to take an application I/O request and send it to the
physical device, then take whatever response comes back from the device and send
it to the application. I/O devices can be divided into two categories −
Block devices − A block device is one with which the driver communicates by
sending entire blocks of data. For example, Hard disks, USB cameras, Disk-On-
Key etc.
Character devices − A character device is one with which the driver
communicates by sending and receiving single characters (bytes, octets). For
example, serial ports, parallel ports, sounds cards etc
Device Controllers
Device drivers are software modules that can be plugged into an OS to handle a
particular device. Operating System takes help from device drivers to handle all I/O
devices.
The Device Controller works like an interface between a device and a device driver.
I/O units (Keyboard, mouse, printer, etc.) typically consist of a mechanical
component and an electronic component where electronic component is called the
device controller.
35
The CPU must have a way to pass information to and from an I/O device. There are
three approaches available to communicate with the CPU and Device.
Special Instruction I/O
Memory-mapped I/O
Direct memory access (DMA)
36
and destination pointers (where to read/write the data), counters to track the number
of transferred bytes, and settings, which includes I/O and memory types, interrupts
and states for the CPU cycles.
Interrupts I/O
An alternative scheme for dealing with I/O is the interrupt-driven method. An
interrupt is a signal to the microprocessor from a device that requires attention.
A device controller puts an interrupt signal on the bus when it needs CPU’s attention
when CPU receives an interrupt, It saves its current state and invokes the
appropriate interrupt handler using the interrupt vector (addresses of OS routines to
handle various events). When the interrupting device has been dealt with, the CPU
continues with its original task as if it had never been interrupted.
Interrupt handling
Interrupts are responses by the processor to a process/event that needs immediate
attention from the software.
Interrupts alert the processor and serves a request for the CPU to interrupt the
currently executing program/code when permitted, in order so that the event can be
processed within good time. If the response is accepted from the processor, the
processor will respond by suspending its current activities (saving its state), and thus
executing a function called an interrupt handler to deal with the event.
37
Types of Interrupts
Interrupts signals as mentioned above, are a response to software or hardware
events in the system. These events are classified as software interrupts or hardware
interrupts.
A. Hardware Interrupt
A hardware interrupt is an electronic alerting signal sent to the processor from an
external device, like a disk controller or an external peripheral. For example, when
we press a key on the keyboard or move the mouse, they trigger hardware interrupts
which cause the processor to read the keystroke or mouse position.
B. Software Interrupt
A software interrupt is caused either by an exceptional condition or a special
instruction in the instruction set which causes an interrupt when it is executed by the
processor. For example, if the processor's arithmetic logic unit runs a command to
divide a number by zero, to cause a divide-by-zero exception, thus causing the
computer to abandon the calculation or display an error message.
Furthermore, software interrupts can also be triggered unexpectedly, by the program
execution errors. These are referred to as traps or exceptions.
Trap Interrupt
The trap is a signal raised by a user The interrupt is a signal to the CPU
program instructing the operating emitted by hardware that indicates an
system to perform some functionality event that requires immediate
immediately. attention.
It is a synchronous process. It is an asynchronous process.
All traps are interrupt. Not all the interrupts are traps.
It may happen only from the software It may happen from the hardware and
devices. software devices.
A user program instruction generates it. Hardware devices generate it.
It is also known as a software interrupt. It is also known as a hardware interrupt.
It executes the specific functionality in It forces the CPU to trigger a specific
the operating system and gives control interrupt handler routine.
to the trap handler.
DEADLOCK
A process in operating system uses resources in the following ways:
Requests a resource
Use the resource
Releases the resource
DEADLOCK DETECTION
If a system does not employ either a deadlock prevention or deadlock avoidance
algorithm then a deadlock situation may occur. In this case:
Apply an algorithm to examine state of system to determine whether deadlock
has occurred or not.
Apply an algorithm to resolve the deadlock.
Race Condition
A race condition is categorized as either a critical or non-critical race condition. The
critical race conditions are those conditions that occur when the order of the internal
variable regulates the last state of the machine. On the other hand, the non-critical
race conditions are those conditions which occur when the order of internal variables
does not regulate the last state of the machine.
40
Semaphores are integer variables that are used to solve the critical section problem
by using two atomic operations, wait and signal that are used for process
synchronization.
The definitions of wait and signal are as follows –
Wait: The wait operation decrements the value of its argument S, if it is positive. If S
is negative or zero, then no operation is performed.
Signal: The signal operation increments the value of its argument S.
Types of Semaphores
There are two main types of semaphores i.e. counting semaphores and binary
semaphores.
Counting Semaphores: These are integer value semaphores and have an
unrestricted value domain. These semaphores are used to coordinate the resource
access, where the semaphore count is the number of available resources. If the
resources are added, semaphore count automatically incremented and if the
resources are removed, the count is decremented.
Binary Semaphores: The binary semaphores are like counting semaphores but
their value is restricted to 0 and 1. The wait operation only works when the
semaphore is 1 and the signal operation succeeds when semaphore is 0. It is
sometimes easier to implement binary semaphores than counting semaphores.
Advantages of Semaphores
Some of the advantages of semaphores are as follows −
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.
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.
Semaphores are implemented in the machine independent code of the
microkernel. So, they are machine independent.
Disadvantages of Semaphores
Some of the disadvantages of semaphores are as follows −
Semaphores are complicated so the wait and signal operations must be
implemented in the correct order to prevent deadlocks.
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.
41
Semaphores may lead to a priority inversion where low priority processes may
access the critical section first and high priority processes later.
42