0% found this document useful (0 votes)
21 views55 pages

Operating Systems Course Overview MMC104

Uploaded by

vinaykumar47670
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views55 pages

Operating Systems Course Overview MMC104

Uploaded by

vinaykumar47670
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ATME COLLEGE OF ENGINEERING

13th KM Stone, Bannur Road, Mysuru - 570 028

DEPARTMENT OF COMPUTER APPLICATIONS

Course Title: OPERATING SYSTEM

Course CODE: 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)

Post Graduates will be able to:

PO-1. Foundation Knowledge :


Apply knowledge of mathematics, programming logic and coding fundamentals for
solution architecture and problem solving.
PO-2. Problem Analysis :
Identify, review, formulate and analyze problems for primarily focusing on customer
requirements using critical thinking frameworks.
PO-3. Development of Solutions:
Design, develop and investigate problems with as an innovative approach for
solutions incorporating ESG/SDG goals.
PO-4. Modern Tool Usage:
Select, adapt and apply modern computational tools such as development of
algorithms with an understanding of the limitations including human biases.
PO-5. Individual and Teamwork :
Function and communicate effectively as an individual or a team leader in diverse
and multidisciplinary groups. Use methodologies such as agile.
PO-6. Project Management and Finance:
Use the principles of project management such as scheduling, work breakdown
structure and be conversant with the principles of Finance or profitable project management.
PO-7. Ethics:
Commit to professional ethics in managing software projects with financial
aspects, learn to use new technologies for cyber security and insulate customers from
malware.
PO-8. Life-long Learning :
Change management skills and the ability to learn, keep up with contemporary
technologies and ways of working.
COURSE DETAILS

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

Memory Management Strategies Basic Hardware, Swapping, Contiguous Memory Allocation,


Segmentation, Paging, Virtual Memory Management Background, Demand Paging, Page
Replacement.
Module 5: File System
File System File concept, Access methods, Directory overview Implementing File System
Allocation methods, Free Space Management Case Studies on Patents: Case study of Curcuma
(Turmeric) Patent, Case study of Neem Patent, Case study of Basmati patent, IP Organizations in
India, Schemes and Programs.
Textbooks
1. Abraham Silberschatz, Peter Baer Galvin, Greg Gagne: Operating Systems Principles, 10th
Edition, Wiley India, 2019.

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.

COURSE ASSESSMENT DETAILS

Assessment Details (both CIE and SEE)


 The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester
End Exam (SEE) is 50%. The minimum passing mark for the CIE is 50% of the
maximum marks. Minimum passing marks in SEE is 40% of the maximum marks
of SEE. A student shall be deemed to have satisfied the academic requirements and
earned the credits allotted to each subject/ course if the student secures not less than
50% (50 marks out of 100) in the sum total of the CIE (Continuous Internal
Evaluation) and SEE (Semester End Examination) taken together.
 Continuous Internal Evaluation:
1. Two Unit Tests each of 25 Marks
2. Two assignments each of 25 Marks or one Skill Development Activity of 50
marks
3. to attain the COs and POs
4. The sum of two tests, two assignments/skill Development Activities, will be
scaled down to 50 marks
5. CIE methods /question paper is designed to attain the different levels of bloom’s
taxonomy as per the outcome defined for the course.

 Semester End Examination :


1. The SEE question paper will be set for 100 marks and the marks scored will be
proportionately reduced to 50.
2. The question paper will have ten full questions carrying equal marks.
3. Each full question is for 20 marks. There will be two full questions (with a maximum
of four subquestions) from each module.
4. Each full question will have a subquestion covering all the topics under a module.
5. The students will have to answer five full questions, selecting one full question from
each module

5
MODULE 1

INTRODUCTION TO OPERATINGSYSTEMS, STRUCTURES


OPERATING SYSTEM

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.

What Operating systems do


 A computer system can be roughly divided into four components:
 The Hardware,
 The Operating System,
 The Application Program,
 The Users.

FIG: ABSTRACT VIEW OF COMPONENTS OF A COMPUTER SYSTEM

 The OS must support the following tasks:


a. Provide the facility to create, modification of programs & data files using on Editors.

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.

 The Role of operating systems can be viewed from two viewpoints:


 The user and
 The system.

User Views:

The user view of the computer depends on the interface used.

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

 Some users may use a terminal connected to a mainframe or minicomputers.


Other users may access the same computer through other terminals. These users
may share resources and exchange information. In this case the OS is designed
to maximize resource utilization-so that all available CPU time, memory & I/O are
used efficiently.

 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 acts as a manager of resources.

 The OS must decide how to allocate resources to programs and the users so that it
can operate the computer system efficiently and fairly.

 Resources can be either


1. CPU Time,
2. memory space,
3. file storage space,
4. I/O devices and so on.

 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:

 A modern general-purpose computer system consists of

1. one or more CPUs and


2. a number of device controllers connected through a common bus that provides
access to shared memory (Figure 1.2).

Figure 1.2 A modern computer system.

 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).

 The bootstrap program must load the operating system.

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

 Interaction is achieved through a sequence of load or store instructions to specific


memory addresses. The load instruction moves a word from main memory to an
internal register within the CPU, whereas the store instruction moves the content
of a register to main memory.

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

 Most computer systems provide secondary storage as an extension of main memory.


The main requirement for secondary storage is that it be able to hold large quantities
of data permanently.

 The most common secondary-storage device is a magnetic disk, which provides


storage for both programs and data.

 The wide variety of storage systems in a computer system can be organized in a


hierarchy (Figure 1.4) according to speed and cost.

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

 To start an I/O operation,

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

Figure 1.5 how a modern computer system works

 Figure 1.5 shows the interplay of all components of a computer system.

Computer-System Architecture
 Single-Processor Systems
 Multiprocessor Systems
 Clustered Systems

Single-Processor Systems

 On this system, there is one main CPU.

 The CPU is capable of executing a general-purpose instruction set, including instructions


from user processes. Almost all systems have other special-purpose processors as well.

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

 For example, a disk-controller microprocessor receives a sequence of requests from the


main CPU and implements its own disk queue and scheduling algorithm.

 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

 Multiprocessor systems are having two or more processors in close communication,


sharing the computer
1. bus
2. the clock,
3. memory, and
4. peripheral devices.

 Multiprocessor systems have three main advantages:

1. Increased throughput. By increasing the number of processors, we expect o get


more work done in less time.

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.

3. Increased reliability. If functions can be distributed properly among several


processors, then the failure of one processor will not halt the system, only slow it
down. If we have ten processors and one fails, then each of the remaining nine
processors can pick up a share of the work of the failed processor.

The ability to continue providing service proportional to the level of surviving


hardware is called graceful degradation.

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.

 The multiple-processor systems in use today are of two types.

1. Some systems use asymmetric multiprocessing, in which each processor is assigned a


specific task. A master processor controls the system; the other processors either look
to the master for instruction or have predefined tasks. This scheme defines a master-
slave relationship. The master processor schedules and allocates work to the slave
processors.

Ex: Sun's operating system SunOS Version 4 provided asymmetric multiprocessing,

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

 Clustered systems gather together multiple CPUs to accomplish computational work,


in this they are composed of two or more individual systems coupled together.

 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:

1. A layer of cluster software runs on the cluster nodes.

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.

 Clustering are of two types

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.

Figure 1.8 General structure of a clustered system

Operating System Structure

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

Figure 1.9 Memory layout for a multiprogrammed system

 In a non-multi-programmed system, the CPU would sit idle. In a multi-programmed


system, the operating system simply switches to, and executes, another job. When that job
needs to wait, the CPU is switched to another job, and so on.

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

 Multi-programmed systems provide an environment in which the various system resources


(for example, CPU, memory, and peripheral devices) are utilized effectively, but they do
not provide for user interaction with the computer system.

 Time sharing (or multitasking) is a logical extension of multiprogramming. In time-


sharing systems, the CPU executes multiple jobs by switching among them, but the
switches occur so frequently that the users can interact with each program while it is
running.

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

 A time-shared operating system uses CPU scheduling and multiprogramming to provide


each user with a small portion of a time-shared computer. Each user has at least one
separate program in memory.

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

Figure 1.10 Transition from user to kernel mode

 This architectural enhancement is useful for many other aspects of system operation as
well.

1. At system boot time, the hardware starts in kernel mode.

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.

 A timer can be set to interrupt the computer after a specified period.

 The period may be fixed (for example,1/60 second) or variable (for example, from 1
millisecond to 1 second).

 A variable timer is generally implemented by a fixed-rate clock and a counter. The


operating system sets the counter. Every time the clock ticks, the counter is decremented.
When the counter reaches 0, an interrupt occurs.

 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 program in execution is a process.

 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:

1. Creating and deleting both user and system processes.


2. Suspending and resuming processes
3. Providing mechanisms for process synchronization
4. Providing mechanisms for process communication
5. Providing mechanisms for deadlock handling

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

3. Allocating and de-allocating memory space as needed.

Storage Management

1. File-System Management
2. Mass-Storage Management
3. Caching

13
1. File-System Management

 A file is a collection of related information defined by its creator. Commonly files


represent programs (both source and object forms) and data.

 Data files maybe numeric, alphabetic, alphanumeric, or binary.

 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

 Caching is an important principle of computer systems.

 Information is normally kept in some storage system (such as main memory).

 As it is used, it is copied into a faster storage system—the cache—on a temporary


basis.

 When we need a particular piece of information,


1. We first check whether it is in the cache.
2. If information is in cache, we use the information directly from the cache;
3. If it is not there, we use the information from the source, putting a copy in the cache
under the assumption that we will need it again soon.

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

 The increment operation proceeds by


1. first issuing an I/O operation to copy the disk block on which A resides to main
memory.
2. This operation is followed by copying A to the cache and to an internal register.
3. Thus, the copy of A appears in several places: on the magnetic disk, in main
memory, in the cache, and in an internal register (see Figure 1.12).
4. Once the increment takes place in the internal register, the value of A differs in the
various storage systems.

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.

 The I/O subsystem consists of several components:


1. A memory-management component that includes buffering, caching, and spooling
2. A general device-driver interface
3. Drivers for specific hardware devices.

 Only the device driver knows the peculiarities of the specific device to which it is
assigned.

Protection and Security

 Protection is a mechanism of controlling the access of processes or users to the resources


defined by a computer system.

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

 The attacks include


1. Viruses and worms
2. Denial of Service (DOS)
3. Identity theft

 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

 A distributed system is a collection of physically separate, possibly heterogeneous


computer systems that are networked to provide the users with access to the various
resources that the system maintains.

16
 Access to a shared resource increases
1. computation speed
2. functionality
3. data availability and
4. reliability

 A network is a communication path between two or more systems.

 Networks vary by the


1. protocols used
2. distances between nodes and
3. Transport media.

 Common network protocol are


1. TCP/IP
2. ATM.

 Networks are characterized based on the distances between their nodes.


1. A local-area network (LAN) connects computers within a building.
2. A wide-area network (WAN) usually links buildings, cities, or countries.
3. A metropolitan-area network (MAN) could link buildings within a city.

 The media to carry networks are equally varied. They include


1. copper wires,
2. fiber strands, and
3. wireless transmissions.

Special-Purpose Systems

1. Real-Time Embedded Systems


2. Multimedia Systems
3. Handheld Systems

1. Real-Time Embedded Systems

 Embedded system devices are found everywhere, from car engines and manufacturing
robots to VCRs and microwave ovens.

 They tend to have very specific tasks.

 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

1. Automobile engines and

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.

 Multimedia describes a wide range of applications. These include

1. audio files such as MP3


2. DVD movies
3. video conferencing
4. live webcasts of speeches

3. Handheld Systems

 Handheld systems include


1. PDAs and
2. cellular telephones.
 Main challenge faced by developers of handheld systems: Limited size of devices.

 Because of small size, most handheld devices have a


1. small amount of memory,
2. slow processors, and
3. small display screens.

Computing Environments

1. Traditional Computing
2. Client-Server Computing
3. Peer-to-Peer Computing
4. Web-Based Computing

1. Traditional Computing

 Used in office environment:


 PCs connected to a network, with servers providing file and print services.
 Used in home networks:

18
 At home, most users had a single computer with a slow modem.
 Some homes have firewalls to protect their networks from securitybreaches.

 Web technologies are stretching the boundaries of traditional computing.


 Companies establish portals, which provide web accessibility to their internal
servers.
 Network computers are terminals that understand web computing.
 Handheld PDAs can connect to wireless networks to use company's web portal.

 Systems were either batch or interactive.


 Batch system processed jobs in bulk, with predetermined input.
 Interactive systems waited for input from users.

2. Client-Server Computing

 Servers can be broadly categorized as (Figure 1.10):


1) Compute servers and
2) File servers
1. Compute-server
 System provides an interface to which a client can send a request to perform an
action (for example, read data).
 In response, the server executes the action and sends back results to the client.
2. File-server system provides a file-system interface where clients can create, read, and
delete files.
For example: web server that delivers files to clients running web browsers

Figure 1.10 General structure of a client–server system

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:

In a client-server system, the server is a bottleneck; but in a peer-to-peer system, services


can be provided by several nodes distributed throughout the network.

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.

Figure 1.11 Peer-to-peer systems with no centralized service.

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.

 In load balancing, network connection is distributed among a pool of similar servers.

 More devices becoming networked to allow web access

 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

Operating System Services

 An operating system provides an environment for the execution of programs.

 It provides certain services to programs and to the users of those programs.

Figure 1.12 A view of OS services

 OS provides two sets of services,


i. one set of service for user
ii. and another set of services for system
Operating-system services provide functions that are helpful to the user
1. User Interface
 Almost all OS have a user-interface (UI).
 Different interfaces are:
i) CLI (Command Line Interface)
This uses
 text commands and
 method for entering the text commands.
ii) Batch Interface
 Commands & directives to control those commands are entered into
files, and those files are executed.
iii) GUI (Graphical User Interface)
 The interface is a window-system with a pointing-device to
1. direct I/0
2. choose from menus and
3. Make selections.
2. Program execution. The system must be able to load a program into memory and to
run that program. The program must be able to end its execution, either normally or
abnormally.
3. I/O operations. A running program may require I/O, which may involve a file or an
I/O device. For specific devices, special functions may be desired.

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

 In message passing, packets of information are moved between processes by OS.

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.

Another set of operating-system functions


1) Resource Allocation
 When multiple users are logged on the system at the same time, resources must be
allocated to each of them.
 The OS manages different types of resources.
 Some resources (say CPU cycles) may have special allocation code.
 Other resources (say I/O devices) may have general request & release code.
2) Accounting
 We want to keep track of
i. which users use how many resources and
ii. which kinds of resources.
 This record keeping may be used for
i. accounting (so that users can be billed) or
ii. gathering usage-statistics.
3) Protection
 When several separate processes execute concurrently, it should not be possible
for one process to interfere with the others or with the OS itself.
 Protection involves ensuring that all access to resources is controlled.
 Security starts with each user having authenticated to the system by means of a
password.
User Operating-System Interface

 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

 System calls provide an interface to the services made available by an operating


system.

 These calls are generally available as routines written in C and C++

 The programmers design programs according to an API.

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

 Three general methods are used to pass parameters to the OS:


1) via registers.
2) Using a table in memory & the address is passed as a parameter in a register
(Figure 1.16).
3) The use of a stack is also possible where parameters are pushed onto a stack
and popped off the stack by the OS.

Figure 1.15 Example of how system calls are used

23
Figure 1.16 Passing of parameters as a table

Types of System Calls

2) Process control
3) File management
4) Device management
5) Information maintenance
6) Communications

1) Process Control

 System calls used:


 end, abort
 load, execute
 create process, terminate process
 get process attributes, set process attributes
 wait for time
 wait event, signal event
 allocate and free memory

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

 The OS must transfer control to the next invoking command interpreter.


 Command interpreter then reads next command.
 In interactive system, the command interpreter simply continues with next
command.
• In GUI system, a pop-up window will request action from user. How to deal with
new process?

 A process executing one program can load and execute another program.

 Where to return control when the loaded program terminates?

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 should be able to control the execution of a process. i.e. we should be able to


determine and reset the attributes of a process such as:
 Job’s priority or
 Maximum execution time

 We may also want to terminate process that we created if we find that it


 is incorrect or
 is no longer needed.

 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

 System calls used:


 create file, delete file
 open, close
 read, write, reposition
 get file attributes, set file attributes

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

 File attributes include


 file name
 file type
 protection codes and
 Accounting information.

25
3) Device Management

 System calls used:


 request device, release device;
 read, write, reposition;
 get device attributes, set device attributes;
 logically attach or detach devices.

 A program may need additional resources to execute.

 Additional resources may be


→ memory
→ tape drives or
→ files.

 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

 System calls used:


 get time or date, set time or date
 get system data, set system data
 get process, file, or device attributes
 set process, file, or device attributes

 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

 System calls used:


 create, delete communication connection
 send, receive messages
 transfer status information
 attach or detach remote devices

 Two models of communication.


1) Message-passing model and
2) Shared Memory Model

Message Passing Model

 Information is exchanged through an IPC provided by OS. (IPC=inter process


communication).

 Steps for communication:

1) Firstly, a connection must be opened using open connection system-call.


2) Each computer has a host-name, such as an IP name.
Similarly, each process has a process-name, which is translated into an equivalent
identifier. The get hostid & get processid system-calls do this translation.
3) Then, identifiers are passed to the open and close system-calls.
4) The recipient-process must give its permission for communication to take
place with an accept connection system-call.(The processes that will be
receiving connections are called daemons processes).
5) Daemon processes
 execute a wait for connection system-call and
 are awakened when a connection is made.

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 shared memory


 is determined by the processes and
 Are not under the control of OS.

 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).

 They can be divided into these categories:

 Six categories of system-programs:

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

 Programming-language support. Compilers, assemblers, debuggers and


interpreters for common programming languages (such as C, C++, Java, Visual
Basic, and PERL) are often provided to the user with the operating system.

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.

 Communications. These programs provide the mechanism for creating virtual


connections among processes, users, and computer systems. They allow users to
send messages to one another's screens, to browse web pages, to send electronic-
mail messages, to log in remotely, or to transfer files from one machine to another

Operating system Design and Implementation

Design goals

 The first problem in designing a system is to


 Define goals and
 Define specifications.

 The design of the system will be affected by


 choice of hardware and
 type of system such as
1) batch or time shared
2) single user or multiuser

 Two basic groups of requirements: 1) User goals and


2) System goals
User goals

 The system should be


 convenient to use
 easy to learn and to use
 Reliable, safe, and fast.
System goals

 The system should be


 easy to design
 implement, and maintain
 Flexible, reliable, error free, and efficient.

Mechanisms and policies

 Mechanisms determine how to do something.

 Policies determine what will be done.

 Separating policy and mechanism is important for flexibility.

29
 Policies change over time; mechanisms should be general.

Implementation

 OS's are nowadays written in higher-level languages like C/C++

 Advantages of higher-level languages:


 Faster development and
 OS is easier to port.

 Disadvantages of higher-level languages:


 Reduced speed and
 Increased storage requirements.

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.

 Disadvantages: MS-DOS vulnerable to errant (or malicious) programs, causing entire


system crashes when user programs fail.

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

Figure MS-DOS layer structure

30
2. UNIX

 It was initially limited by hardware functionality.

 Two parts of UNIX (Figure below):


1) Kernel and
2) System programs.

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

 The kernel provides following functions through system calls:


1. file system
2. CPU scheduling and
3. Memory management.

 Disadvantage:
1) Difficult to enhance, as changes in one section badly affects other areas.

Figure UNIX system structure

Layered Approach

 The OS is divided into a number of layers.

 Each layer is built on the top of another layer.

 The bottom layer is the hardware.

The highest is the user interface (Figure below).

 A layer is an implementation of an abstract-object.

i.e. The object is made up of


 data and

31
 operations that can manipulate the data.

 The layer consists of a set of routines that can be invoked by higher-layers.

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

Figure : A layered operating system.


Microkernels

 Main function:
 To provide a communication facility between
 client program and
 Various services running in user-space.

 Communication is provided by message passing (Figure).

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:

1) Performance decreases due to increased system function overhead.

Figure Architecture of a typical microkernel

Modules

 The kernel has


 set of core components and
 Dynamic links in additional services during boot time( or run time).

 Seven types of modules in the kernel (Figure 1.21):


1) Scheduling classes
2) File systems
3) Loadable system calls
4) Executable formats
5) STREAMS modules
6) Miscellaneous
7) Device and bus drivers

 The top layers include


 application environments and
 Set of services providing a graphical interface to applications.

33
 Kernel environment consists primarily of
 Mach microkernel and
 BSD kernel.

 Mach provides
 memory management;
 support for RPCs & IPC and
 Thread scheduling.

 BSD component provides


 BSD command line interface
 support for networking and file systems and
 implementation of POSIX APIs

 The kernel environment provides an I/O kit for development of


 device drivers and
 Dynamic loadable modules (which Mac OS X refers to as kernel extensions).

Figure 1.21 Solaris loadable modules

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

 The virtual-machine provides


 an interface that is identical to the underlying hardware (Figure below).
 a (virtual) copy of the underlying computer to each process.

34
Figure: (a) Non-virtual machine, (b) Virtual machine

Benefits of 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.

3. There is no direct sharing of resources. Two approaches to provide sharing have


been implemented. First, it is possible to share a file-system volume and thus to share
files. Second, it is possible to define a network of virtual machines, each of which
can send information over the virtual communications network.

4. A virtual-machine system is a perfect vehicle for operating-systems research and


development. Changing an operating system is a difficult task.

5. Another advantage of virtual machines for developers is that multiple operating


systems can be running on the developer's workstation concurrently.

6. Similarly, quality-assurance engineers can test their applications in multiple


environments without buying, powering, and maintaining a computer for each
environment.

7. A major advantage of virtual machines in production data-center use is system


which involves taking two or more separate systems and running them in virtual
machines on one system. Such physical-to-virtual conversions result in resource
optimization, as many lightly used systems can be combined to create one more
heavily used system.

8. Any virtual machine will run on any virtualization platform.

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.

Figure: Solaris 10 with two containers


Examples

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

 OS is designed to run on any of a class of machines.

However, the system must be configured for each specific computer site

 SYSGEN is used for configuring a system for each specific computer site

 SYSGEN program must determine:

1) What CPU will be used?


2) How will boot disk be formatted?
3) How much memory is available?
4) What devices are available?
5) What OS options are desired?
 A system-administrator can use the above information to modify a copy of the source
code of the OS

System Boot
 Booting means starting a computer by loading the kernel.

 Bootstrap program is a code stored in ROM.

 The bootstrap program

 locates the kernel


 loads the kernel into main memory and
 Starts execution of kernel.

 The bootstrap program can perform a variety of tasks. Usually, one task is to run
diagnostics to determine the state of the machine

 OS must be made available to hardware so hardware can start it.

37
MODULE 1

PROCESS MANAGEMENT
Process Concept

 A process is a program in execution.

 It also includes (Figure below):

1) Program Counter to indicate the current activity.

2) Registers Content of the processor.

3) Process Stack contains temporary data.

4) Data Section contains global variables.

5) Heap is memory that is dynamically allocated during process run time.

Figure: Process in memory


 A program by itself is not a process.
1) A process is an active-entity.
2) A program is a passive-entity such as an executable-file stored on disk.

 A program becomes a process when an executable-file is loaded into memory.

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.

Process Control Block (PCB)

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

Figure: Process control block (PCB).

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.

Figure: the ready queue and various I/O device queues

 A common representation of a process scheduling is a queuing diagram, as shown in Figure below.


Each rectangular box represents a queue.
 Two types of queues are present: the ready queue and a set of device queues. The circles represent
the resources that serve the queues, and the arrows indicate the flow of processes in the system.
 A new process is initially put in the ready queue. It waits there until it is selected for execution, or
is dispatched. Once the process is allocated the CPU and is executing, one of several events could
occur:
 The process could issue an I/O request and then be placed in an I/O queue.
 The process could create a new sub-process and wait for the sub-process's termination.

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.

Figure: Queuing-diagram representation of process scheduling.

Schedulers

 Three types of schedulers:


1) Long-term scheduler
2) Short-term scheduler and
3) Medium-term schedulers

Long-Term Scheduler Short-Term Scheduler


Also called job scheduler. Also called CPU scheduler.
Selects which processes should be brought into Selects which process should be executed next
the ready-queue. and allocates CPU.
Need to be invoked only when a process leaves Need to be invoked to select a new process for
the system and therefore executes much less the CPU and therefore executes much more
frequently. frequently.
May be slow, minutes may separate the creation Must be fast, a process may execute for Only a
of one new process and the next. few milliseconds.
Controls the degree of multiprogramming.

 Processes can be described as either:


1) I/O-bound Process
 Spends more time doing I/O operation than doing computations.

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.

Figure: Addition of medium-term scheduling to the queuing diagram

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.

Figure: Diagram showing CPU switch from process to process.

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

 Two options exist when a process creates a new process:


1) The parent & the children execute concurrently.
2) The parent waits until all the children have terminated.

 Two options exist in terms of the address-space of the new process:


1) The child-process is a duplicate of the parent-process (it has the same program and data

as the parent).
2) The child-process has a new program loaded into it.

Process creation in UNIX

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

2) The return value for the fork() is


nonzero pid of the child for the parent-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.

Figure : Process creation.

7
Process Termination

 A process terminates when it executes the last statement (in the program).

 Then, the OS deletes the process by using exit() system-call.

 Then, the OS de-allocates all the resources of the process. The resources include
→ memory
→ open files and
→ I/0 buffers.

 Process termination can occur in following cases:


→ A process can cause the termination of another process via TerminateProcess()
system-call.

→ Users could arbitrarily kill the processes.

 A parent terminates the execution of children for following reasons:


3) The child has exceeded its usage of some resources.
4) The task assigned to the child is no longer required.
5) The parent is exiting, and the OS does not allow a child to continue.

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

 Processes executing concurrently in the OS may be 1) Independent processes or


2) Co-operating processes.
1) A process is independent if
i) The process cannot affect or be affected by the other processes.
ii) The process does not share data with other processes.
2) A process is co-operating if
i) The process can affect or be affected by the other processes.
ii) The process shares data with other processes.

 Advantages of process co-operation:


1) Information Sharing
 Since many users may be interested in same piece of information (ex: shared file).

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.

 Two basic models of IPC (Figure below): 1) Shared-memory and


2) Message passing.

Figure: Communications models, (a) Message passing, (b) Shared memory

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.

 A message-passing facility provides at least two operations:


 send(message) and
 receive(message)

 Messages sent by a process can be of either


 fixed or
 variable size.

 If only fixed-sized messages can be sent, the system-level implementation is straightforward.

 Variable-sized messages require a more complex system-level implementation, but the


programming task becomes simpler.

 A communication-link must exist between processes to communicate

 Three methods for implementing a link:

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.

Naming (Direct and Indirect)

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

• receive (Q, message)—Receive a message from process Q.

 A communication link in this scheme has the following properties:


• A link is established automatically between every pair of processes that want to communicate.
The processes need to know only each other's identity to communicate.

• A link is associated with exactly two processes.

• Between each pair of processes, there exists exactly one link.

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

• receive(A, message)—Receive a message from mailbox A.

 In this scheme, a communication link has the following properties:


• A link is established between a pair of processes only if both members of the pair have a shared
mailbox.

• A link may be associated with more than two processes.

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

• Blocking receive. The receiver blocks until a message is available.

• Non-blocking receive. The receiver retrieves either a valid message or a null.

 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

Common questions

Powered by AI

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 .

You might also like