UNIT 1 Notes-OS
UNIT 1 Notes-OS
means of more complex processors. Designers have found that the best way to improve performance to take
advantage of advances in hardware is to put multiple processors and a substantial amount of cache memory
on a single chip
An example of a multicore system is the Intel Core i7, which includes four x86 processors, each with a
dedicated L2 cache, and with a shared L3 cache. One mechanism Intel uses to make its caches more
effective is prefetching, in which the hardware examines memory access patterns and attempts to fill the
caches speculatively with data that s likely to be requested soon.
The OS provides certain services to programs and to the users of those programs.
1. 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
(indicating error).
2. I/O operations: A running program may require I/O. This I/O may involve a file or an I/O device.
3. File-system manipulation: The program needs to read, write, create, delete files.
4. Communications: In many circumstances, one process needs to exchange
Information with another process. Such communication can occur in two major ways. Thefirst
takes place between processes that are executing
on the same computer; the second takes place between processes that are executing on different
computer systems that are tied together by a computer network.
5. Error detection: The operating system constantly needs to be aware of possible errors. Errors
may occur in the CPU and memory hardware (such as a memory error or a power failure),
in I/O devices (such as a parity error on tape, a connection failure on a network, or lack of paper
in the printer), and in the user program (such as an arithmetic overflow, an attempt to access an illegal
memory location, or a too-great use of CPU time). For each type of error, the operating system should
take the appropriate action to ensure correct and consistent computing.
6. Resource allocation: Different types of resources are managed by the Os.When there are multiple
users or multiple jobs running at the same time, resources must be allocated to each of them.
7. Accounting: We want to keep track of which users use how many and which kinds of computer
resources. This record keeping may be used for accounting or simply for accumulating usage
statistics.
8. Protection: The owners of information stored in a multiuser computer system may want
to control use of that information. Security of the system is also important.
OPERATING SYSTEM STRUCTURES
SIMPLE STRUCTURE:
In MS-DOS, application programs are able to access the basic I/O routines to write
directly to the display and disk drives. Such freedom leaves MS-DOS vulnerable to errant (or
malicious) programs, causing entire system to crash when user programs fail.
MICROKERNEL APPROACH:
In the mid-1980s, researchers at Carnegie Mellon University developed an operating system
called Mach that modularized the kernel using the microkernel approach. provide
minimal process and memory management, in addition to a communication facility.
The main function of the micro kernel is to provide a communication facility between the
client program and the various services running in user space. One benefit of the microkernel approach is
ease of extending the operating system. All new services are added to user space and consequently do
not require modification of the kernel. The microkernel also provides more security and reliability,
since most services are running as user, rather than kernel-processes.
can suffer from decreased performance due to increased system
function overhead.
MODULES:
The current methodology for operating-system design involves using object-oriented
programming techniques to create a modular kernel. Here, the kernel has a set of core components
and links in additional services either during boot time or during run time. Such a
strategy uses dynamically loadable modules.
Such a design allows the kernel to provide core services yet also allows certain features
to be implemented dynamically.
SYSTEM CALLS
A system call is a request that a program makes to the kernel through a software
interrupt. System calls provide the interface between a process and the operating system.
These calls are generally available as assembly-language instructions. Certain systems allow
system calls to be made directly from a high-level language program, in which case the calls
normally resemble predefined function or subroutine calls.
TYPES OF SYSTEM CALLS:
Traditionally, System Calls can be categorized in six groups, which are: Process Control,
File Management, Device Management, Information Maintenance, Communications and
Protection.
PROCESS CONTROL
A running program needs to be able to stop execution either normally or abnormally.
When execution is stopped abnormally, often a dump of memory is taken and can be examined
with a debugger.
Following are functions of process control:
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
FILE MANAGEMENT
We first need to be able to create and delete files. Either system call requires the name of the file
and perhaps some of the file's attributes.
Once the file is created, we need to open it and to use it. We may also read, write, or reposition.
Finally, we need to close the file, indicating that we are no longer using it.
We may need these same sets of operations for directories if we have a directory structure for
organizing files in the file system.
In addition, for either files or directories, we need to be able to determine the values of various
attributes and perhaps to reset them if necessary. File attributes include the file name, a file type,
protection codes, accounting information, and so on
Functions:
Create, delete file
Open, close
Read, write, reposition
Get file attributes, set file attributes
DEVICE MANAGEMENT
A process may need several resources to execute - main memory, disk drives, access to files, and
so on. If the resources are available, they can be granted, and control can be returned to the user
process. Otherwise, the process will have to wait until sufficient resources are available.
The various resources controlled by the OS can be thought of as devices. Some of these devices are
physical devices (for example, tapes), while others can be thought of as abstract or virtual devices
(for example, files).
Once the device has been requested (and allocated to us), we can read, write, and (possibly)
reposition the device, just as we can with files.
In fact, the similarity between I/O devices and files is so great that many OSs, including UNIX,
merge the two into a combined file-device structure.
A set of system calls is used on files and devices. Sometimes, 1/0 devices are identified by special
file names, directory placement, or file attributes.
Functions:
Request device, release device
Read, write, reposition
Get device attributes, set device attributes
Logically attach or detach devices
INFORMATION MAINTENANCE
Many system calls exist simply for the purpose of transferring information between the user
program and the OS. For example, most systems have a system call to return the current time and
date.
Other system calls may return information about the system, such as the number of current users,
the version number of the OS, the amount of free memory or disk space, and so on.
In addition, the OS keeps information about all its processes, and system calls are used to access
this information. Generally, calls are also used to reset the process information.
Functions:
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
COMMUNICATIONS
There are two common models of interprocess communication: the message-passing model and the
shared-memory model. In the message-passing model, the communicating processes exchange
messages with one another to transfer information.
In the shared-memory model, processes use shared memory creates and shared memory attaches
system calls to create and gain access to regions of memory owned by other processes.
Recall that, normally, the OS tries to prevent one process from accessing another process's memory.
Shared memory requires that two or more processes agree to remove this restriction. They can then
exchange information by reading and writing data in the shared areas.
Message passing is useful for exchanging smaller amounts of data, because no conflicts need be
avoided. It is also easier to implement than is shared memory for intercomputer communication.
Shared memory allows maximum speed and convenience of communication, since it can be done
at memory speeds when it takes place within a computer. Problems exist, however, in the areas of
protection and synchronization between the processes sharing memory.
Functions:
Create, delete communication connection
Send, receive messages
Transfer status information
Attach or detach remote devices
PROTECTION
Get File Security, Set File Security
Get Security Group, Set Security Group
SYSTEM PROGRAMS
System programs provide a convenient environment for program development and execution.
They can be divided into several categories:
1. File management: These programs create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories.
2. Status information: The status such as date, time, amount of available memory or
diskspace, number of users or similar status information.
3. File modification: Several text editors may be available to create and
modify the content of files stored on disk or tape.
4. Programming-language support: Compilers, assemblers, and interpreters for common
programming languages are often provided to the user with the operating system.
5. Program loading and execution: The system may provide absolute loaders, relocatable loaders,
linkage editors, and overlay loaders.
6. Communications: These programs provide the mechanism for creating virtual connections
among processes, users, and different computer systems. (email, FTP, Remote log in)
7. Application programs: Programs that are useful to solve common
problems, or to perform common operations.
Eg. Web browsers, database systems.
Operating-System Generation
It is possible to design, code, and implement an operating system specifically for one machine
at one site. More commonly, however, operating systems are designed to run on any of a class of machines
at a variety of sites with a variety of peripheral configurations. The system must then be configured or
generated for each specific computer site, a process sometimes known as system generation (SYSGEN).
The operating system is normally distributed on disk or CD-ROM. To generate a system, we use
a special program. The SYSGEN program reads from a given file, or asks the operator of thesystem for
information concerning the specific configuration of the hardware system, or probes the hardware directly
to determine what components are there. The following kinds of information must be determined.
What options (extended instruction sets, floating-point arithmetic, and so on) are installed?
For multiple CPU systems, each CPU must be described.
Some systems will determine this value themselves by referencing memory location after
memory location until an "illegal address" fault is generated. This procedure defines the final
legal address and hence the amount of available memory.
The system will need to know how to address each device (the device number), the device
interrupt number, the device's type and model, and any special device characteristics.
What operating-system options are desired, or what parameter values are to be used? These
options or values might include how many buffers of which sizes should be used, what type
of CPU-scheduling algorithm is desired, what the maximum number of processes to be
supported is, and so on. Once this information is determined, it can be used in several ways.
System Boot
After an operating system is generated, it must be made available for use by the
hardware. But how does the hardware know where the kernel is or how to load that kernel?
The procedure of starting a computer by loading the kernel is known as booting the system.
On most computer systems, a small piece of code known as the bootstrap program or
bootstrap loader locates the kernel, loads it into main memory, and starts its execution. Some
computer systems, such as PCs, use a two-step process in which a simple bootstrap loader fetches a
more complex boot program from disk, which in turn loads the kernel.
When a CPU receives a reset event for instance, when it is powered up or rebooted the
instruction register is loaded with a predefined memory location, and execution starts there. At that
location is the initial bootstrap program.
This program is in the form of read-only memory (ROM), because the RAM is in an
unknown state at system startup. ROM is convenient because it needs no initialization and
cannot be infected by a computer virus.
The bootstrap program can perform a variety of tasks. Usually, one task is to run diagnostics
to determine the state of the machine. If the diagnostics pass, the program can continue with the
booting steps. It can also initialize all aspects of the system, from CPU registers to device
controllers and the contents of main memory.
Sooner or later, it starts the operating system. Some systems such as cellular phones, PDAs,
and game consoles store the entire operating system in ROM. Storing the operating system in
ROM is suitable for small operating systems, simple supporting hardware, and rugged operation.
A problem with this approach is that changing the bootstrap code requires changing the
ROM hardware chips. Some systems resolve this problem by using erasable programmable read-
only memory (EPROM), which is read-only except when explicitly given a command to become
writable.
All forms of ROM are also known as firmware, since their characteristics fall somewhere
between those of hardware and those of software. A problem with firmware in general is
that executing code there is slower than executing code in RAM. Some systems store the
operating system in firmware and copy it to RAM for fast execution. A final issue with
firmware is that it is relatively expensive, so usually only small amounts are available.
EVALUATION OF OPERATING SYSTEMS.
Stages of Evaluation
Serial Processing
Users access the computer in series. From the late 1940's to mid 1950's, the programmer
interacted directly with computer hardware i.e., no operating system.
These machines were run with a console consisting of display lights, toggle
switches, some form of input device and a printer. Programs in machine code are loaded
with the input device like card reader.
If an error occur the program was halted and the error condition was indicated by
lights. Programmers examine the registers and main memory to determine error. If the program is
success, then output will appear on the printer.
Main problem here is the setup time. That is single program needs to load source
program into memory, saving the compiled (object) program and then loading and
linking together.
Multiple jobs are executed by the CPU by switching between them, but the switches
occur so frequently. Thus, the user can receives an immediate response. For example, in a
transaction processing, processor execute each user program in a short burst or quantum of
computation. That is if n users are present, each user can get time quantum. When the user
submits the command, the response time is seconds at most.
Operating system uses CPU scheduling and multiprogramming to provide each user with a
small portion of a time. Computer systems that were designed primarily as batch systems have
been modified to time-sharing systems.
For example IBM's OS/360.
Time-sharing operating systems are even more complex than multi-programmed operating
systems. As in multiprogramming, several jobs must be kept simultaneously in memory.
OBJECTIVES AND FUNCTIONS OF AN OPERATING SYSTEMS
To ease this chore, a set of system programs is provided. Some of these programs are referred to as
utilities, or library programs. These implement frequently used functions that assist in program creation,
the management of files, and the control of I/O devices. A programmer will make use of these facilities in
developing an application, and the application, while it is running, will invoke the utilities to perform certain
functions.
Three key
interfaces in a typical computer system:
Instruction set architecture (ISA) : The ISA defines the repertoire of machine language instructions
that a computer can follow. This interface is the boundary between hardware and software. Note that both
application programs and utilities may access the ISA directly. For these programs, a subset of the
instruction repertoire is available (user ISA). The OS has access to additional machine language instructions
that deal with managing system resources (system ISA).
Application binary interface (ABI) : The ABI defines a standard for binary portability across programs.
The ABI defines the system call interface to the operating system and the hardware resources and services
available in a system through the user ISA.
Application programming interface (API) : The API gives a program access to the hardware resources
and services available in a system through the user ISA supplemented with high-level language (HLL)
library calls. Any system calls are usually performed through libraries. Using an API enables application
software to be ported easily, through recompilation, to other systems that support the same API.
The memory management hardware in the processor and the OS jointly control the allocation of main
memory, as we shall see. The OS decides when an I/O device can be used by a program in execution and
controls access to and use of files. The processor itself is a resource, and the OS must determine how much
processor time is to be devoted to the execution of a particular user program. In the case of a multiple-
processor system, this decision must span all of the processors.
Modern operating systems are interrupt driven. If there are no processes to execute, OS will sit idle and
wait for some event to happen. Interrupts could be hardware interrupts or software interrupts. The OS is
designed to handle both. A trap (or an exception) is a software generated interrupt caused either by an error
(e.g. divide by zero) or by a specific request from a user program. A separate code segment iswritten
in the OS to handle different types of interrupts. These codes are known as interrupt handlers/ interrupt
service routine. A properly designed OS ensures that an illegal program should not harm the execution of
other programs. To ensure this, the OS operates in dual mode.
The OS is design in such a way that it is capable of differentiating between the execution of OS code and
user defined code. To achieve this OS need two different modes of operations this is thereby controlled by
mode bit added to hardware of computer system as shown in Table 4.
User Mode User Defined codes are executed Mode Bit=1 Creation of word document or in
general user using any application
program
Kernel Mode OS system codes are executed Mode Bit=0 Handling interrupts-Transferring
(also known as supervisor, control of a process from CPU to I/O
system, or privileged mode) on request
User and Kernel Mode of Operating System
When a user application is executing on the computer system OS is working in user mode. On signal of
system call via user application, the OS transits from user mode to kernel mode to service that request as
shown in Fig. 11.
When the user starts the system the hardware starts in monitor/ kernel mode and loads the operating system.
OS has the initial control over the entire system, when instructions are executed in kernel mode. OS then
starts the user processes in user mode and on occurrence of trap, interrupt or system call again switch to
kernel mode and gains control of the system. System calls are designed for the user programs through which
user can ask OS to perform tasks reserved for operating system. System calls usually take the form of the
trap. Once the OS service the interrupt it transfers control back to user program hence user mode by setting
mode bit=1.
The dual mode of operation protects the operating system from errant users, and errant users from one
another by designating some of the machine instructions that may cause harm as privilegedinstructions.
These instructions can execute 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 the instruction as illegal and
traps to the operating system. Examples of privileged instructions:
Timer
Since OS operates in dual mode it should maintain control over CPU. The system should not allow a user
application:
1. To be stuck in an infinite loop
2. To fail to call system services
3. Never return control to the OS
To achieve this goal, we can use timer. This timer control mechanism will interrupt the system at a specified
period; thereby preventing user program from running too long. This can be implemented either as fixed
timer or variable timer
Additional Topics
Virtualization technology enables a single PC or server to simultaneously run multiple operating systems
or multiple sessions of a single OS
A machine with virtualization software can host numerous applications, including those that run on
different operating systems, on a single platform
The host operating system can support a number of virtual machines, each of which has the
characteristics of a particular OS
The solution that enables virtualization is a virtual machine monitor (VMM), or hypervisor
A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the opera
The resources of the physical computer are shared to create the virtual machines.
1. CPU scheduling can create the appearance that users have their own processor.
2. Spooling and a file system can provide virtual card readers and virtual line printers.
The virtual-machine concept provides complete protection of system resources since each virtual
machine is isolated from all other virtual machines.
A virtual-machine system is a perfect vehicle for operating-systems research and development. System
development is done on the virtual machine, instead of on a physical machine and so does not disrupt
normal system operation.
The virtual machine concept is difficult to implement due to the effort required to provide an exact
duplicate to the underlying machine.