Operating Systems Course Overview MMC104
Operating Systems Course Overview MMC104
SEMESTER: I
Academic Year – 2025-26
INSTITUTIONAL VISION AND MISSION
VISION:
Development of academically excellent, culturally vibrant, socially responsible
and globally competent human resources.
MISSION:
To keep pace with advancements in knowledge and make the students
competitive and capable at the global level.
To create an environment for the students to acquire the right physical, intellectual,
emotional and moral foundations and shine as torchbearers of tomorrow's society.
To strive to attain ever-higher benchmarks of educational excellence.
Program Outcomes (POs)
OPERATING SYSTEMS
Course Code – MMC104 CIE Marks – 50
Teaching Hours / Week (L:P:SDA/T) - 2:0:1 SEE Marks – 50
Total Hours of Pedagogy – 45 Total Marks – 100
Credits - 03 Exam Hours - 03
COURSE SYLLABUS
Module 1: Introduction To Operating Systems
Introduction to Operating Systems, System Structure What operating systems do, Operating
System Operations, Computing Environments, Operating System Services, System Calls, Types
of System Calls, System Programs, Operating System Structure, System Boot Process Concept
Process Concept, Process Scheduling, Interprocess Communication
Module 2: Process Scheduling
Process Scheduling Basic Concepts, Scheduling Criteria, Scheduling Algorithms
Synchronization Background, The Critical Section Problem, Mutex Locks, Semaphores, Classic
Problems of Synchronization: Readers-Writers Problem, Dining Philosophers Problem using
Semaphores
Module 3: Deadlocks
Deadlocks: System model, Deadlock Characterization, Methods for handling deadlocks,
Deadlock Prevention, Deadlock Avoidance, Deadlock Detection and Recovery from Deadlock
Module 4: Memory Management
Reference books
1. D M Dhamdhere: Operating Systems A Concept Based Approach, 3rd Edition, Tata
McGraw Hill, 2017.
2. Harvey M Deital: Operating Systems, 3rdEdition, Addison Wesley, 1990.
5
MODULE 1
An Operating System is a Program that manages the computer hardware and acts as an
intermediary between the user of the computer & the computer hardware.
The goal of OS:
To execute programs.
To make solving user problems easier.
To make the computer convenient to use.
b. Access to Compilers for translating the user program from high level language to
machine language.
c. Provide a Loader program to move the compiled program code to computers memory
for execution.
1
d. Provides Routines that handle the details of I/O programming.
User Views:
Some users may use PC’s. In this the system is designed so that only one user can
utilize the resources and mostly for ease of use where the attention is mainly on
performances and not on the resource utilization.
Other users may connect to the networks of other work station and servers. In
this case OS is designed to compromise between individual visibility & resource
utilization.
System Views:
The OS must decide how to allocate resources to programs and the users so that it
can operate the computer system efficiently and fairly.
An OS is a control program
The OS is needed to control
Operation of I/O devices and
Execution of user program to prevent errors.
2
Computer-System Organization
Computer-System Operation:
Each device controller is in charge of a specific type of device (for example, disk
drives, audio devices, and video displays).
The CPU and the device controllers can execute concurrently, competing for memory
cycles.
For a computer to start running—for instance, when it is powered up or rebooted—
The initial program, or bootstrap program, is executed when the system is powered
on.
Bootstrap program is stored in read-only memory (ROM) or electrically erasable
programmable read-only memory (EEPROM).
Then the OS starts executing the first process such as init and waits for some event to
occur.
When the CPU is interrupted, it stops what it is doing and immediately transfers
execution to interrupt service routine (ISR). The ISR executes; on completion, the
CPU resumes the interrupted computation.
A time line of this operation is shown in Figure 1.3. The interrupt must transfer
control to the appropriate interrupt service routine.
3
Figure 1.3 Interrupt time line for a single process doing output.
Storage Structure
Computer programs must be in main to be executed. Main memory is the only large
storage area that the processor can access directly.
We want the programs and data to reside in main memory permanently. This
arrangement usually is not possible for the following two reasons:
1. Main memory is usually too small to store all needed programs and data
permanently.
2. Main memory is a volatile storage device that loses its contents when power is
turned off or otherwise lost.
The higher levels are expensive, but they are fast. As we move down the hierarchy,
the cost per bit generally decreases, whereas the access time generally increases.
4
Figure 1.4 Storage-devices Hierarchy
I/O Structure
A computer system consists of CPUs and multiple device controllers that are connected
through a common bus. Each device controller is in charge of a specific type of device.
A device controller maintains some local buffer storage and a set of special-purpose
registers. The device controller is responsible for moving the data between the peripheral
devices that it controls and its local buffer storage.
Typically, operating systems have a device driver for each device controller.
This device driver understands the device controller and presents a uniform interface to the
device to the rest of the operating system.
1. The device driver loads the appropriate registers within the device controller.
2. The device controller, in turn, examines the contents of these registers to determine
what action to take (such as "read a character from the keyboard").
3. The controller starts the transfer of data from the device to its local buffer.
4. Once the transfer of data is complete, the device controller informs the device driver
via an interrupt that it has finished its operation.
5. The device driver then returns control to the operating system, possibly returning the
data or a pointer to the data if the operation was a read.
This form of interrupt-driven I/O is fine for moving small amounts of data but can
produce high overhead when used for bulk data movement such as disk I/O.
5
To solve this problem, direct memory access (DMA) is used. After setting up buffers,
pointers, and counters for the I/O device, the device controller transfers an entire block of
data directly to or from its own buffer storage to memory, with no intervention by the
CPU.
Computer-System Architecture
Single-Processor Systems
Multiprocessor Systems
Clustered Systems
Single-Processor Systems
The special purpose processor may come in the form of device-specific processors, such as
disk, keyboard, and graphics controllers; or, on mainframes, they may come in the form of
more general-purpose processors, such as I/O processors that move data rapidly among the
components of the system.
All of these special-purpose processors run a limited instruction set and do not run
user processes.
This arrangement relieves the main CPU of the overhead of disk scheduling. PCs contain a
microprocessor in the keyboard to convert the keystrokes into codes to be sent to the CPU.
6
In other systems or circumstances, special-purpose processors are low-level components
built in to the hardware.
Multiprocessor Systems
2. Economy of scale. Multiprocessor systems can cost less than equivalent multiple
single-processor systems, because they can share peripherals, mass storage, and
power supplies.
Some systems go beyond graceful degradation and are called fault tolerant, because
they can suffer a failure of any single component and still continue operation.
2. The other systems use symmetric multiprocessing (SMP), in which each processor
performs all tasks within the operating system. SMP means that all processors are
peers; no master-slave relationship exists between processors. Figure 1.6 illustrates a
typical SMP architecture.
7
Figure 1.6 Symmetric multiprocessing architecture.
A recent trend in CPU design is to include multiple compute cores on a single chip. In
essence, these are multiprocessor chips. Two-way chips are becoming mainstream, while
N-way chips are going to be common in high-end systems.
In Figure 1.7, we have a dual-core design with two cores on the same chip. In this design,
each core has its own register set as well as its own local cache; other designs might use a
shared cache or a combination of local and shared caches.
Figure 1.7 A dual-core design with two cores placed on the same chip
Clustered Systems
They are linked via a local-area network (LAN) or a faster interconnects such as Infini
Band.
Advantage: Clustering usually used to provide high-availability service; that is, service
will continue even if one or more systems in the cluster fail. High availability is generally
obtained by adding a level of redundancy in the system.
8
Working:
2. Each node can monitor one or more of the others (over the LAN).
3. If the monitored machine fails, the monitoring machine can take ownership of its
storage and restart the applications that were running on the failed machine.
1. asymmetric clustering
2. Symmetric clustering
In asymmetric clustering, one machine is in hot-standby mode while the other is running
the applications. The hot-standby host machine does nothing but monitor the active server.
If that server fails, the hot-standby host becomes the active server.
In symmetric mode, two or more hosts are running applications, and are monitoring each
other. This mode is obviously more efficient, as it uses all of the available hardware. It does
require that more than one application be available to run.
A single user cannot, in general, keep either the CPU or the I/O devices busy at all times.
Multiprogramming increases CPU utilization by organizing jobs (code and data) so that
the CPU always has one to execute. The idea is as follows: The operating system keeps
several jobs in memory simultaneously (Figure 1.9).
This set of jobs can be a subset of the jobs kept in the job pool—which contains all jobs
that enter the system—since the number of jobs that can be kept simultaneously in memory
is usually smaller than the number of jobs that can be kept in the job pool.
9
The operating system picks and begins to execute one of the jobs in memory. Eventually,
the job may have to wait for some task, such as an I/O operation, to complete.
Eventually, the first job finishes waiting and gets the CPU back. As long as at least one job
needs to execute, the CPU is never idle.
Time sharing requires an interactive (or hands-on) computer system, which provides
direct communication between the user and the system. The user gives instructions to the
operating system or to a program directly, using a input device such as a keyboard or a
mouse, and waits for immediate results on an output device.
Accordingly, the response time should be short—typically less than one second. A time-
shared operating system allows many users to share the computer simultaneously.
In addition, if several jobs are ready to run at the same time, the system must choose among
them. Making this decision is CPU scheduling.
Finally, running multiple jobs concurrently requires that their ability to affect one another
be limited in all phases of the operating system, including process scheduling, disk storage,
and memory management.
10
Operating-System Operations
1) Dual-Mode Operation
In order to ensure the proper execution of the operating system, we must be able to
distinguish between the execution of operating-system code and user defined code.
two separate modes of operation:
user mode and
kernel mode (also called supervisor mode, system mode, or privileged mode).
A bit, called the mode bit, is added to the hardware of the computer to indicate the current
mode: kernel (0) or user (1).
When the computer system is executing on behalf of a user application, the system is in
user mode.
When a user application requests a service from the operating system (via a system call),
it must transition from user to kernel mode to fulfill the request. This is shown in Figure
1.10.
This architectural enhancement is useful for many other aspects of system operation as
well.
2. The operating system is then loaded and starts user applications in user mode.
3. Whenever a trap or interrupt occurs, the hardware switches from user mode to
kernel mode (i.e changes the state of the mode bit to 0).
4. Thus, whenever the operating system gains control of the computer, it is in kernel
mode.
5. The system always switches to user mode (by setting the mode bit to 1) before
passing control to a user program.
The dual mode of operation provides us with the means for protecting the operating system
from errant users—and errant users from one another.
11
We accomplish this protection by designating some of the machine instructions that may
cause harm as privileged instructions. The hardware allows privileged instructions to be
executed only in kernel mode.
If an attempt is made to execute a privileged instruction in user mode, the hardware does
not execute the instruction but rather treats it as illegal and traps it to the operating system.
The instruction to switch to user mode is an example of a privileged instruction.
When control is given to a user application, the mode is set to user mode. Eventually,
control is switched back to the operating system via an interrupt, a trap, or a system call.
2) Timer
We must prevent a user program from getting stuck in an infinite loop or not calling system
services and never returning control to the operating system.
The period may be fixed (for example,1/60 second) or variable (for example, from 1
millisecond to 1 second).
Before turning over control to the user, the operating system ensures that the timer is set to
interrupt.
Thus, we can use the timer to prevent a user program from running too long. A simple
technique is to initialize a counter with the amount of time that a program is allowed to run.
As long as the counter is positive, control is returned to the user program. When the counter
becomes negative, the operating system terminates the program for exceeding the assigned
time limit.
Process Management
A process needs certain resources—including CPU time, memory, files, and I/O
devices—to accomplish its task.
When the process terminates, the operating system will reclaim any reusable resource
A program by itself is not a process; a program is a passive entity, such as the contents
of a file stored on disk, whereas a process is an active entity.
12
A single-threaded process has one program counter specifying the next instruction to
execute.
A multithreaded process has multiple program counters, each pointing to the next
instruction to execute.
The operating system is responsible for the following activities in connection with
process management:
Memory Management
Main memory is a large array of words or bytes. Main memory is a repository of quickly
accessible data shared by the CPU and I/O devices.
The CPU reads instructions from main memory during the instruction-fetch cycle and
both reads and writes data from main memory during the data-fetch cycle.
The main memory is generally the only large storage device that the CPU is able to address
and access directly.
To improve both the utilization of the CPU and the speed of the computer's response to its
users, general-purpose computers must keep several programs in memory, creating a need
for memory management.
The operating system is responsible for the following activities in connection with memory
management:
1. Keeping track of which parts of memory are currently being used and by whom
2. Deciding which processes (or parts thereof) and data to move into and out of memory
Storage Management
1. File-System Management
2. Mass-Storage Management
3. Caching
13
1. File-System Management
Files are normally organized into directories to make them easier to use.
Finally, when multiple users have access to files, it may be desirable to control by
whom and in what ways (for example, read, write, append) files may be accessed.
The operating system is responsible for the following activities in connection with file
management:
1. Creating and deleting files
2. Creating and deleting directories to organize files
3. Supporting primitives for manipulating files and directories
4. Mapping files onto secondary storage
5. Backing up files on stable (nonvolatile) storage media
2. Mass-Storage Management
Most programs are stored on a disk until loaded into memory and then use the disk as
both the source and destination of their processing.
The operating system is responsible for the following activities in connection with
disk management:
• Free-space management
• Storage allocation
• Disk scheduling.
Because secondary storage is used frequently, it must be used efficiently. The entire
speed of operation of a computer may hinge on the speeds of the disk subsystem and
of the algorithms that manipulate that subsystem.
There are, however, many uses for storage that is slower and lower in than secondary
storage. Backups of disk data, seldom-used data, and long-term archival storage are
some examples.
Magnetic tape drives and their tapes and CD and DVD drives and platters are typical
tertiary storage devices.
14
3. Caching
Without this cache, the CPU would have to wait several cycles while an instruction
was fetched from main memory.
Figure 1.11 shows a storage performance comparison in large workstations and small
servers that shows the need for caching.
Main memory can be viewed as a fast cache for secondary storage, since data in
secondary storage must be copied into main memory for use, and data must be in
main memory before being moved to secondary storage for safe keeping.
15
Figure 1.12 Migration of integer A from disk to register
4. I/O Systems
The peculiarities of I/O devices are hidden from the bulk of the operating system itself
by the I/O subsystem.
Only the device driver knows the peculiarities of the specific device to which it is
assigned.
Protection can improve reliability by detecting latent errors at the interfaces between
component subsystems.
Security means defense of the system from internal and external attacks.
Protection and security require the system to be able to distinguish among all its users.
Most operating systems maintain a list of user names and associated user identifiers (user
IDs).
When a user logs in to the system, the authentication stage determines the appropriate user
ID for the user. That user ID is associated with all of the user's processes and threads.
Distributed Systems
16
Access to a shared resource increases
1. computation speed
2. functionality
3. data availability and
4. reliability
Special-Purpose Systems
Embedded system devices are found everywhere, from car engines and manufacturing
robots to VCRs and microwave ovens.
The systems they run on are usually primitive, and so the operating systems provide limited
features.
Usually, they prefer to spend their time monitoring & managing hardware devices such as
2. Robotic arms.
17
Embedded systems almost always run real-time operating systems.
A real-time system is used when rigid time requirements have been placed on the operation
of a processor.
A real-time system has well-defined, fixed time constraints. Processing must be done
within the defined constraints, or the system will fail.
2. Multimedia Systems
Multimedia data consist of audio and video files as well as conventional files.
These data differ from conventional data in that multimedia data must be
delivered(streamed) according to certain time restrictions.
3. Handheld Systems
Computing Environments
1. Traditional Computing
2. Client-Server Computing
3. Peer-to-Peer Computing
4. Web-Based Computing
1. Traditional Computing
18
At home, most users had a single computer with a slow modem.
Some homes have firewalls to protect their networks from securitybreaches.
2. Client-Server Computing
3. Peer-to-Peer Computing
All nodes are considered peers, and each may act as either a client or a server(Figure 1.11).
Advantage:
19
A node must first join the network of peers.
Determining what services are available is done in one of two general ways:
1. When a node joins a network, it registers its service with a centralized lookup service
on the network.
Any node desiring a specific service first contacts this centralized lookup
service to determine which node provides the service.
2. A peer broadcasts a request for the service to all other nodes in the network. The node
(or nodes) providing that service responds to the peer.
4. Web-Based Computing
This includes
1. PC
2. handheld PDA &
3. cell phones
Load balancer is a new category of devices to manage web traffic among similar servers.
Use of operating systems like Windows 95, client-side, have evolved into Linux and
Windows XP, which can be clients and servers
20
OPERATING-SYSTEM STRUCTURES
21
4. File-system manipulation. Programs need to
1. read and
2. write files and directories.
3. to create and delete file them by name,
4. search for a given file, and list file information.
5. allow or deny access to files or directories based on file ownership.
5. Communications
In some situations, one process needs to communicate with another process.
Communications may be implemented via
1. Shared memory or
2. Message passing
6. Error detection
Errors may occur in
CPU & memory-hardware (ex: power failure)
I/O devices (ex: lack of paper in the printer) and
user program (ex: arithmetic overflow
For each type of error, OS should take appropriate action to ensure correct &
consistent computing.
There are two fundamental approaches for users to interface with the operating
system. One technique is to provide a command-line interface or command interpreter
22
that allows users to directly enter commands that are to be performed by the operating
system. The second approach allows the user to interface with the operating system
via a graphical user interface or GUI.
System Calls
The API
→ defines a set of functions that are available to the programmer (Figure 1.15).
→ includes the parameters passed to functions and the return values.
The functions that make up an API invoke the actual system-calls on behalf of the
programmer.
Benefits of API:
1) Program portability.
2) Actual system-calls are more detailed (and difficult) to work with than the API
available to the programmer.
23
Figure 1.16 Passing of parameters as a table
2) Process control
3) File management
4) Device management
5) Information maintenance
6) Communications
1) Process Control
A running program needs to be able to halt its execution either normally (end) or
abnormally (abort).
If program runs into a problem, error message may be generated and dumped into a file.
This file can be examined by a debugger to determine the cause of the problem.
A process executing one program can load and execute another program.
24
The answer depends on the existing program:
1) If control returns to the existing program when the new program terminates, we
must save the memory image of the existing program. (Thus, we have effectively
created a mechanism for one program to call another program).
2) If both programs continue concurrently, we created a new process to be
multiprogrammed.
We may need to wait for processes to finish their execution. We may want to wait for a
specific event to occur.
The processes should then signal when that event has occurred.
2) File Management
Working procedure:
1) We need to create and delete files.
2) Once the file is created,
we need to open it and to use it.
we may also read or write.
3) Finally, we need to close the file.
We need to be able to
determine the values of file-attributes and
reset the file-attributes if necessary.
25
3) Device Management
If the resources are available, they can be granted, and control can be returned to the user
program; if the resources are unavailable, the program may have to wait until sufficient
resources are available.
Files can be thought of as virtual devices. Thus, many of the system calls used for files are
also used for devices.
In multi-user environment,
1) We must first request the device, to ensure exclusive use of it.
2) After we are finished with the device, we must release it.
Once the device has been requested (and allocated), we can read and write the device.
Due to lot of similarity between I/O devices and files, OS (like UNIX) merges the two
into a combined file-device structure.
UNIX merges I/O devices and files into a combined file-device structure.
4) Information Maintenance
Many system calls exist simply for the purpose of transferring information between the
user program and the OS.
For ex,
1) Most systems have a system call to return
current time and
current date.
2) Other system calls may return information about the system, such as
→ number of current users
26
→ version number of the OS
→ amount of free memory or disk space.
The OS keeps information about all its processes, and there are system calls to access this
information.
Communication
6) Then, client & server exchange messages by read message and write message
system calls.
7) Finally, the close connection system-call terminates the communication.
Advantages:
1) Useful when smaller numbers of data need to be exchanged.
2) It is also easier to implement than is shared memory.
27
Shared Memory Model
Processes use map memory system-calls to gain access to regions of memory owned by
other processes.
Several processes exchange information by reading and writing data in the shared
memory.
The processes are also responsible for ensuring that they are not writing to the
same location simultaneously.
Advantage:
1) Shared memory allows maximum speed and convenience of communication,
Disadvantage:
1) Problems exist in the areas of protection and synchronization.
System Programs
They provide a convenient environment for program development and execution. (System
programs also known as system utilities).
File management. These programs create, delete, copy, rename, print, dump, list,
and generally manipulate files and directories.
Status information. Some programs simply ask the system for the date, time,
amount of available memory or disk space, number of users, or similar status
information. Others are more complex, providing detailed performance, logging,
and debugging information
File modification. Several text editors may be available to create and modify the
content of files stored on disk or other storage devices. There may also be special
commands to search contents of files or perform transformations of the text.
28
Program loading and execution. Once a program is assembled or compiled, it
must be loaded into memory to be executed. The system may provide absolute
loaders, re-locatable loaders, linkage editors, and overlay loaders. Debugging
systems for either higher-level languages or machine language are needed as well.
Design goals
29
Policies change over time; mechanisms should be general.
Implementation
Operating-System Structure
Simple Structure
1. MS-DOS
Advantages: These operating systems started as small, simple, and limited systems and
then grew beyond their original scope. MS-DOS is an example of such a system.
It was written to provide the most functionality in the least space, so it was not divided
into modules carefully.
Figure below shows its structure. In MS-DOS, the interfaces and levels of functionality
are not well separated. For instance, application programs are able to access the basic I/O
routines to write directly to the display and disk drives.
MS-DOS was also limited by the hardware of its era. Because the Intel 8088 for which it
was written provides no dual mode and no hardware protection.
30
2. UNIX
The kernel is further separated into a series of interfaces and device drivers.
Everything below the system-call interface and above the physical hardware is the kernel.
Disadvantage:
1) Difficult to enhance, as changes in one section badly affects other areas.
Layered Approach
31
operations that can manipulate the data.
Higher-layer
does not need to know how lower-layer operations are implemented
Needs to know only what lower-layer operations do.
Advantage:
1) The layered approach is simplicity of construction and debugging.
2) Simplifies debugging and system verification.
3) The design and implementation of the system is simplified. Each layer is
implemented with only those operations provided by lower level layers.
4) Each layer hides the existence of certain data structures, operations, and hardware
from higher-level layers.
Disadvantages:
1) Difficulty with the layered approach involves appropriately defining the
various layers. Because a layer can use only lower-level layers, careful planning
is necessary.
2) Less efficient than other types.
Main function:
To provide a communication facility between
client program and
Various services running in user-space.
32
All non-essential components are
removed from the kernel and
Implemented as system- & user-programs.
Advantages:
1) Ease of extending the OS. (New services are added to user space w/o
modification of kernel).
2) Easier to port from one hardware design to another.
3) Provides more security & reliability. (If a service fails, rest of the OS remains
untouched.).
4) Provides minimal process and memory management.
Disadvantage:
Modules
33
Kernel environment consists primarily of
Mach microkernel and
BSD kernel.
Mach provides
memory management;
support for RPCs & IPC and
Thread scheduling.
Virtual Machines
The fundamental idea behind a virtual machine is to abstract the hardware of a single
computer (the CPU, memory, disk drives, network interface cards, and so forth) into
several different execution environments, thereby creating the illusion that each separate
execution environment is running its own private computer.
An operating system can create the illusion that a process has its own processor with its
own (virtual) memory.
Normally, a process has additional features, such as system calls and a file system that are
not provided by the bare hardware
34
Figure: (a) Non-virtual machine, (b) Virtual machine
1. Virtual machine is fundamentally related to being able to share the same hardware
but runs different operating systems concurrently.
2. The host system is protected from the virtual machines. A virus inside a guest
operating system might damage that operating system but is unlikely to affect the host
or the other guests.
I. Para-virtualization
Para-virtualization presents the guest with a system that is similar but not identical
to the guest's preferred system.
35
The guest must be modified to run on the Para-virtualized hardware. The gain for
this extra work is more efficient use of resources and a smaller virtualization
layer.
The operating system and its devices are virtualized, providing processes within a
container with the impression that they are the only processes on the system.
One or more containers can be created, and each can have its own applications,
network stacks, network address and ports, user accounts, and so on. CPU
resources can be divided up among the containers and the system wide processes.
VMware
VMware Workstation is a popular commercial application that abstracts Intel X86 and
compatible hardware into isolated virtual machines.
The architecture of such a system is shown in Figure below. In this scenario, Linux is running
as the host operating system; and FreeBSD, Windows NT, and Windows XP are running as
guest operating systems.
The virtualization layer is the heart of VMware, as it abstracts the physical hardware into
isolated virtual machines running as guest operating systems. Each virtual machine has its
own virtual CPU, memory, disk drives, network interfaces, and so forth.
36
Figure: VMware architecture.
Operating-System Generation
However, the system must be configured for each specific computer site
SYSGEN is used for configuring a system for each specific computer site
System Boot
Booting means starting a computer by loading the kernel.
The bootstrap program can perform a variety of tasks. Usually, one task is to run
diagnostics to determine the state of the machine
37
MODULE 1
PROCESS MANAGEMENT
Process Concept
Process State
As a process executes, it changes state. The state of a process is defined in part by the
current activity of that process. Each process may be in one of the following states:
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.
1
Figure: Diagram of process state.
Each process is represented in the operating system by a process control block (PCB)—also called
a task control block. A PCB is shown in Figure.
It contains many pieces of information associated with a specific process, including these:
1. Process state. The state may be new, ready, running, and waiting, halted, and so on.
2. Program counter. The counter indicates the address of the next instruction to be executed for
this process.
3. CPU registers. They include accumulators, index registers, stack pointers, and general-
purpose registers, plus any condition-code information.
4. CPU-scheduling information. This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
5. Memory-management information. This information may include such information as the
value of the base and limit registers, the page tables, or the segment tables, depending on the
memory system used by the operating system.
6. Accounting information. This information includes the amount of CPU and real time used,
time limits, account numbers, job or process numbers, and so on.
7. I/O status information. This information includes the list of I/O devices allocated to the
process, a list of open files, and so on.
2
Process Scheduling
The objective of multiprogramming is to have some process running at all times, to maximize CPU
utilization.
Scheduling Queues
As processes enter the system, they are put into a job queue, which consists of all processes in the
system.
The processes that are residing in main memory and are ready and waiting to execute are kept on
a list called the ready queue. This queue is generally stored as a linked list.
A ready-queue header contains pointers to the first and final PCBs in the list. Each PCB includes
a pointer field that points to the next PCB in the ready queue. The system also includes other queues.
When a process is allocated the CPU, it executes for a while and eventually quits, is interrupted, or
waits for the occurrence of a particular event, such as the completion of an I/O request.
3
The process could be removed forcibly from the CPU, as a result of an interrupt, and be put
back in the ready queue.
In the first two cases, the process eventually switches from the waiting state to the ready state and
is then put back in the ready queue. A process continues this cycle until it terminates, at which time
it is removed from all queues and has its PCB and resources de-allocated.
Schedulers
4
Many short CPU bursts.
2) CPU-bound Process
Spends more time doing computations than doing I/O operation.
Few very long CPU bursts.
Why long-term scheduler should select a good process mix of I/O-bound and CPU-bound
processes ?
Ans: 1) If all processes are I/0 bound, then
i) Ready-queue will almost always be empty, and
ii) Short-term scheduler will have little to do.
2) If all processes are CPU bound, then
i) I/0 waiting queue will almost always be empty (devices will go unused) and
System will be unbalanced.
Some operating systems, such as time-sharing systems, may introduce an additional, intermediate
level of scheduling. This medium-term scheduler is diagrammed in Figure.
The key idea behind a medium-term scheduler is that sometimes it can be advantageous to
remove processes from memory (and from active contention for the CPU) and thus reduce the
degree of multiprogramming.
Later, the process can be reintroduced into memory, and its execution can be continued where it
left off. This scheme is called swapping. The process is swapped out, and is later swapped in, by
the medium-term scheduler.
Swapping may be necessary to improve the process mix or because a change in memory
requirements has overcommitted available memory, requiring memory to be freed up.
Context Switch
Context-switch means saving the state of the old process and switching the CPU to another
process.
The context of a process is represented in the PCB of the process; it includes
5
value of CPU registers
process-state and
Memory-management information.
Disadvantages:
1) Context-switch time is pure overhead, because the system does no useful work
while switching.
2) Context-switch times are highly dependent on hardware support.
Operations on Processes
1) Process Creation and
2) Process Termination
Process Creation
A process may create several new processes, via a create-process system call, during the course of
execution.
The creating process is called a parent process, and the new processes are called the children of
that process.
Operating systems identify processes according to a unique process identifier (or pid), which is
typically an integer number.
A process will need certain resources (CPU time, memory, files, I/O devices) to accomplish its task.
6
Child-process may
get resources directly from the OS or
get resources of parent-process. This prevents any process from overloading the system
as the parent).
2) The child-process has a new program loaded into it.
In UNIX, each process is identified by its process identifier (pid), which is a unique integer.
A new process is created by the fork() system-call (Figure 1.29 & 1.30).
The new process consists of a copy of the address-space of the original process.
Both the parent and the child continue execution with one difference:
1) The return value for the fork() is
zero for the new (child) process.
Typically, the exec() system-call is used after a fork() system-call by one of the two processes to
replace the process's memory-space with a new program.
The parent can issue wait() system-call to move itself off the ready-queue.
7
Process Termination
A process terminates when it executes the last statement (in the program).
Then, the OS de-allocates all the resources of the process. The resources include
→ memory
→ open files and
→ I/0 buffers.
In some systems, if a process terminates, then all its children must also be terminated.
This phenomenon is referred to as cascading termination.
8
Interprocess Communication(IPC)
2) Computation Speedup
We must break the task into subtasks.
Each subtask should be executed in parallel with the other subtasks.
The speed can be improved only if computer has multiple processing elements such
as
→ CPUs or
→ I/O channels.
3) Modularity
Divide the system-functions into separate processes or threads.
4) Convenience
An individual user may work on many tasks at the same time.
For ex, a user may be editing, printing, and compiling in parallel.
9
1. Shared-Memory Systems
Typically, a shared-memory region resides in the address space of the process creating the shared-
memory segment.
To illustrate the concept of cooperating processes, let's consider the producer-consumer problem.
A producer process produces information that is consumed by a consumer process.
One solution to the producer-consumer problem uses shared memory. To allow producer and
consumer processes to run concurrently, we must have available a buffer of items that can be
filled by the producer and emptied by the consumer.
This buffer will reside in a region of memory that is shared by the producer and consumer processes.
A producer can produce one item while the consumer is consuming another item. So that the
consumer does not try to consume an item that has not yet been produced.
Two types of buffers can be used:
1) Unbounded-Buffer places no practical limit on the size of the buffer.
2) Bounded-Buffer assumes that there is a fixed buffer-size.
Advantages:
1) Allows maximum speed and convenience of communication.
2) Faster.
2. Message-Passing Systems
Message passing provides a mechanism to allow processes to communicate and to synchronize their
actions without sharing the same address space and is particularly useful in a distributed
environment, where the communicating processes may reside on different computers connected by
a network.
10
1) Direct or indirect communication.
2) Symmetric or asymmetric communication.
3) Automatic or explicit buffering.
Two operations:
1) send(P,message): Send a message to process P.
2) receive(Q,message): Receive a message from process Q.
Advantages:
1) Useful for exchanging smaller amounts of data („.‟ No conflicts need beavoided).
2) Easier to implement.
3) Useful in a distributed environment.
Processes that want to communicate must have a way to refer to each other. They can use either
direct or indirect communication.
In direct communication, each process that wants to communicate must explicitly name the
recipient or sender of the communication. In this scheme, the send() and receive() primitives are
defined as:
• send(P, message)—Send a message to process P.
This scheme exhibits symmetry in addressing; that is, both the sender process and the receiver
process must name the other to communicate.
A variant of this scheme employs asymmetry in addressing. Here, only the sender names the
recipient; the recipient is not required to name the sender.
• send(P, message)—Send a message to process P.
• receive(id, message)—-Receive a message from any process; the variable id is set to the name of
the process with which communication has taken place.
The disadvantage in both of these schemes is the limited modularity of the resulting process
definitions. Changing the identifier of a process may necessitate examining all other process
definitions.
Indirect communication: the messages are sent to and received from mailboxes, or ports. A
mailbox can be viewed abstractly as an object into which messages can be placed by processes and
from which messages can be removed.
11
Each mailbox has a unique identification. a process can communicate with some other process via
a number of different mailboxes. Two processes can communicate only if the processes have a
shared mailbox, however.
The send () and receive () primitives are defined as follows:
• send(A, message)—Send a message to mailbox A.
• Between each pair of communicating processes, there may be a number of different links, with
each link corresponding to one mailbox.
A mailbox may be owned either by a process or by the operating system. If the mailbox is owned
by a process (that is, the mailbox is part of the address space of the process), then we distinguish
between the owner (who can only receive messages through this mailbox) and the user (who can
only send messages to the mailbox).
Synchronization.
Message passing may be either blocking or non-blocking— also known as synchronous and
asynchronous.
• Blocking send. The sending process is blocked until the message is received by the receiving
process or by the mailbox.
• Non-blocking send. The sending process sends the message and resumes operation.
When both send() and receive() are blocking, we have a rendezvous between the sender and the
receiver. The solution to the producer-consumer problem becomes trivial when we use blocking
send() and receive0 statements.
The producer merely invokes the blocking send() call and waits until the message is delivered to
either the receiver or the mailbox. Likewise, when the consumer invokes receive (), it blocks until
a message is available.
Buffering
Whether communication is direct or indirect, messages exchanged by communicating processes
reside in a temporary queue. Basically, such queues can be implemented in three ways:
• Zero capacity. The queue has a maximum length of zero; thus, the link cannot have any messages
waiting in it. In this case, the sender must block until the recipient receives the message.
12
• Bounded capacity. The queue has finite length n; thus, at most n messages can reside in it. If the
queue is not full when a new message is sent, the message is placed in the queue (either the message
is copied or a pointer to the message is kept), and the sender can continue execution without waiting.
The links capacity is finite, however. If the link is full, the sender must block until space is available
in the queue.
• Unbounded capacity. The queues length is potentially infinite; thus, any number of messages
can wait in it. The sender never blocks.
i) ing
13
The bootstrap program is crucial for initializing a computer system; it is executed when the system is powered on, residing in ROM or EEPROM. Its primary role is to load the operating system into main memory, enabling the OS to start executing the first process, such as init, and manage the system thereafter. It also establishes the initial environment by loading system variables and configurations necessary for system operation . Without it, the computer cannot transition from hardware to an operational state ready for user and system demands .
Process creation and termination are vital in managing system resources and ensuring efficient operation by controlling how processes enter and exit the system. Process creation allows the system to utilize resources efficiently by dynamically generating processes to handle tasks as needed. The management of these processes, through mechanisms like unique identifiers (pids) and parent-child relationships, ensures that resources such as memory and CPU time are allocated effectively . Process termination frees up resources, allowing reallocation to other tasks and preventing resource allocation conflicts. It also ensures that processes do not exceed resource usage limits, maintaining system balance and preventing system overloads . Overall, these operations help maintain a stable and efficient operating environment by adapting to varying workload demands .
Process synchronization in operating systems faces significant challenges, primarily due to the need to manage access to shared resources by concurrent processes without causing conflicts or inconsistencies. Issues such as deadlocks, race conditions, and starvation can arise when synchronization is poorly managed. These challenges affect system performance by potentially leading to system deadlocks—where no progress is made—or inefficient resource allocation that lowers throughput and increases latency. Suitable mechanisms like semaphores, mutexes, and monitors are used to prevent these issues, ensuring smooth and efficient process collaboration and resource sharing . Proper synchronization is crucial for maintaining data integrity and achieving optimal system performance .
Operating systems deploy various scheduling algorithms to optimize process execution and resource allocation, enhancing system efficiency and process management. Short-term schedulers quickly decide which process in the ready queue should be executed next to optimize CPU utilization. Long-term schedulers maintain a balanced mix of I/O-bound and CPU-bound processes to avoid resource bottlenecks. Medium-term schedulers engage in swapping to manage memory allocation dynamically, improving process mix and system responsiveness. These algorithms ensure fair and efficient distribution of resources, minimizing wait times and maximizing throughput . The appropriate selection of these algorithms depends on system requirements and workload characteristics, impacting overall performance .
Secondary storage significantly impacts the memory hierarchy by providing essential and persistent data storage that complements the volatile nature of main memory. Main memory is usually not large enough to hold all programs and data permanently due to its limited size and volatile nature. Secondary storage, often a magnetic disk, offers a permanent, high-capacity storage solution for data and programs not currently in use . It is indispensable as it serves as a backup to main memory, enabling data retrieval even after power loss. Additionally, it facilitates larger hierarchical storage systems by organizing data efficiently in a cost-effective manner, influencing performance, speed, and cost considerations within the memory hierarchy .
Caching is crucial in computer systems as it significantly enhances performance by reducing the time the CPU waits for data retrieval from main memory. By storing frequently accessed data closer to the CPU, caching reduces latency and increases throughput, allowing faster data access compared to fetching from slower secondary storage. The presence of caches ensures that the CPU can perform more efficiently, minimizing idle cycles that occur when fetching data from main memory or disk storage . The impact is substantial in systems demanding high-speed processing, such as large workstations and servers .
The interrupt service routine (ISR) is a critical component in operating systems, enabling effective management of process execution by handling interrupts. An ISR allows the CPU to immediately respond to important events or signals by pausing the current execution and transferring control to the appropriate service routine when an interrupt occurs. This mechanism is crucial for time-sensitive processes, ensuring high system responsiveness and enabling concurrent execution of processes and I/O operations. After the ISR executes, control returns to the interrupted process, maintaining system stability and efficiency . The ISR plays a vital role in multi-tasking environments, where processes must be swiftly and seamlessly managed .
In a multi-user environment, the operating system balances the needs of different users by designing the system to either maximize resource utilization or ensure ease of use, depending on the interface being used . Challenges include efficiently managing shared resources like CPU time, memory, and I/O devices, while preventing errors and ensuring fair allocation among users. Additionally, the OS must manage simultaneous access and communication between different terminals and networked workstations, sometimes compromising between visibility for individual users and overall resource efficiency .
A process in an operating system is an active entity representing a program in execution. In contrast, a program is a passive entity, such as an executable file stored on disk. A process includes the program code, the program counter, registers, and dynamic resources like memory. Throughout its lifecycle, a process changes state—from being new (created), to running (actively executing), to waiting (for resources or events), to ready (waiting to be assigned to the processor), and finally to terminated (when execution finishes). This dynamic nature of processes enables multitasking and resource optimization in a computing environment .
Protection and security mechanisms in an operating system intersect by providing layered defenses against unauthorized access and potential threats, ensuring system integrity and reliability. Protection mechanisms control access to resources, detecting and preventing errors at component interfaces, which aligns closely with security goals of defending against attacks like viruses, worms, and identity theft . Both mechanisms require strong user identification and authentication processes, managing user IDs and permissions to enforce access controls . They are essential for maintaining a stable computing environment, protecting data integrity, and defending against internal and external threats .