OS - Unit 1
OS - Unit 1
UNIT 1
SYLLABUS
Operating System Principles: what Operating Systems do, Computer System
organization, computer system architecture, Operating System structure,
Computing environments, Operating System Services, User - Operating System
interface, System calls and system programs, Operating System structure.
School of C&IT
REVA University, Bengaluru Page 1
OPERATING SYSTEMS
• The basic hardware components comprise of CPU, memory, I/O devices. The
application program uses these components. The OS controls and co-ordinates the
use of hardware, among various application programs (like compiler, word processor
etc.) for various users.
• The OS allocates the resources among the programs such that the hardware is
efficiently used.
• The operating system is the program running at all the times on the computer. It is
usually called as the kernel.
Views of OS
Operating System can be viewed from two viewpoints: User view and System view
1 User View: The user's view of the OS depends on the type of the user
✓ If the user is using standalone system, then OS is designed for ease of use and
high performances. Here resource utilization is not given importance.
✓ If the users are at different terminals connected to a mainframe or
minicomputers, by sharing information and resources, then the OS is designed
to maximize resource utilization. OS is designed such that the CPU time, memory
and I/O are used efficiently and no single user takes more than the resource
allotted to them
✓ If the users are in workstations, connected to networks and servers, then the
user have a dedicated resources but also share resources such as networking
and servers-files, print servers. Here the OS is designed for both ease of use and
resource availability (files).
School of C&IT
REVA University, Bengaluru Page 2
OPERATING SYSTEMS
✓ Users of hand held systems, expects the OS to be designed for ease of use and
performance per amount of battery life.
✓ Other systems like embedded systems used in home devices (like washing m/c)
and automobiles do not have any user interaction. They are connected to
network either directly by wire or through wireless modems and networking.
School of C&IT
REVA University, Bengaluru Page 3
OPERATING SYSTEMS
Storage Structure
• The CPU can load instructions only from memory, so any programs to run must be
stored there. General-purpose computers run most of their programs from
rewritable memory, called main memory (also called random-access memory, or
RAM).
• Main memory commonly is implemented in a semiconductor technology called
dynamic random-access memory (DRAM).
• Ideally, programs and data are to be resided 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.
• Thus, 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. Most programs (system and application) are
stored on a disk until they are loaded into memory.
• The wide variety of storage systems can be organized in a hierarchy (Figure 1.3)
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.
• The top four levels of memory in Figure 3 may be constructed using semiconductor
memory.
School of C&IT
REVA University, Bengaluru Page 4
OPERATING SYSTEMS
• Volatile storage loses its contents when the power to the device is removed. In the
absence of expensive battery and generator backup systems, data must be written
to non-volatile storage for safekeeping.
• In the hierarchy shown in Figure 1.3, the storage systems above the solid-state disk
are volatile, whereas those including the solid-state disk and below are non-volatile.
I/O Structure
• Storage is only one of many types of I/O devices within a computer. A large portion
of operating system code is dedicated to managing I/O, both because of its
importance to the reliability and performance of a system and because of the
varying nature of the devices.
• A general-purpose computer system consists of CPUs and multiple device
controllers that are connected through a common bus.
• Depending on the controller, more than one device may be attached.
• 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.
• To start an I/O operation, the device driver loads the appropriate registers within
the device controller. 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”).
School of C&IT
REVA University, Bengaluru Page 5
OPERATING SYSTEMS
• The controller starts the transfer of data from the device to its local buffer. Once the
transfer of data is complete, the device controller informs the device driver via an
interrupt that it has finished its operation.
• 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. For other operations,
the device driver returns status information.
• On a single processor system, there is one main CPU capable of executing a general-
purpose instruction set, including instructions from user processes.
• Almost all single processor systems have other special-purpose processors as well.
They 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. Sometimes, they are managed by the operating system, in that the
operating system sends them information about their next task and monitors their
status.
• These systems have two or more processors in close communication, sharing the
computer bus, the clock, memory, and peripheral devices.
• Multiprocessor systems have three main advantages:
• Increased Throughput: Throughput is defined as number of processes computed
per unit time. By increasing the number of processors, the more work can be
done in less time. In multiprocessor system, execution of different programs
take place simultaneously. Even if the number of processors is increased the
performance cannot be simultaneously increased. This is due to the overhead
incurred in keeping all the parts working correctly. The speed-up ratio with N
processors is not N, rather, it is less than N. Thus the speed of the system is not
has expected.
• Economy of Scale: Multiprocessor systems can cost less than equivalent multiple
single-processor systems. As the multiprocessor systems share peripherals,
mass storage, and power supplies, the cost of implementing this system is
economical. If several processes are working on the same data, the data can also
be shared among them.
• Increased reliability: In multiprocessor systems, functions are shared among
several processors. If one processor fails, the system is not halted, it only slows
School of C&IT
REVA University, Bengaluru Page 6
OPERATING SYSTEMS
down. The job of the failed processor is taken up, by other processors. This
ability to continue to operate in spite of failure makes the system fault tolerant.
Fault tolerance requires a mechanism to allow the failure to be detected,
diagnosed, and, if possible, corrected.
There are two types of multiprocessors systems
i Asymmetric Multiprocessing (Master-Slave Architecture) : Here each
processor is assigned a specific task, by the master processor. A master
processor controls the other processors in the system. It schedules and
allocates work to the slave processors. This scheme defines master-slave
relationship.
Ex- Sun's Operating system: SUNOS version 4
ii Symmetric multiprocessing (SMP): The processors are considered as
peers; no master-slave relationship exists between processors. Each
processor performs all tasks within the OS. All the processors have its own
registers and CPU, only memory is shared as shown in figure 4
The benefit of this model is that many processes can run simultaneously. N
processes can run if there are N CPUs—without causing a significant
deterioration of performance. Operating systems like Windows, Windows XP,
Mac OS X, and Linux—now provide support for SMP.
Clustered Systems
School of C&IT
REVA University, Bengaluru Page 7
OPERATING SYSTEMS
1) Simple Structure
School of C&IT
REVA University, Bengaluru Page 8
OPERATING SYSTEMS
2) Layered Approach
✓ The OS is broken into number of layers (levels). Each layer rests on the layer
below it, and relies on the services provided by the next lower layer.
✓ Bottom layer(layer 0) is the hardware and the topmost layer (layer N) is the user
interface as shown in Figure 8.
✓ A typical layer, consists of data structure and routines that can be invoked by
higher-level layer.
School of C&IT
REVA University, Bengaluru Page 9
OPERATING SYSTEMS
• Advantages:
➢ Simplicity of construction and debugging
➢ The layers are selected such that each uses functions and services of only
lower-level layers. Hence simplifies debugging and system verification i.e., the
first layer can be debugged without concerning the rest of the system. Once
the first layer is debugged, its correct functioning is assumed while the 2nd
layer is debugged & so on.
➢ If an error is found during the debugging of a particular layer, the error must
be on that layer because the layers below it are already debugged. Thus the
design & implementation of the system are simplified when the system is
broken down into layers.
➢ A layer doesn‘t need to know how these operations are implemented; it only
needs to know what these operations do.
• Disadvantages:
➢ The various layers must be appropriately defined, as a layer can use only
lower level layers.
➢ Less efficient than other types, because any interaction with layer 0 required
from top layer. The system call should pass through all the layers and finally
to layer 0. This is an overhead.
Figure 8: A Layered OS
3) Microkernels
• The basic idea behind micro kernels is to remove all non-essential services from
the kernel, thus making the kernel as small and efficient as possible.
School of C&IT
REVA University, Bengaluru Page 10
OPERATING SYSTEMS
• Advantages:
➢ System expansion can be easier, because it only involves adding more system
applications, not rebuilding a new kernel.
➢ When the kernel does not have to be modified, the changes are fewer, because
the microkernel is a smaller kernel.
➢ Hence microkernel is smaller kernel.
➢ The microkernel OS is easier to port from one hardware design to another.
➢ Provides more security and reliability, since most services are running as user
programs rather than kernel processes.
• Disadvantages:
➢ Performance is reduced due to increased system function overhead.
School of C&IT
REVA University, Bengaluru Page 11
OPERATING SYSTEMS
• File Systems
• Loadable System calls
• Executable formats
• STREAMS modules
• Miscellaneous
• Device and bus drivers
✓ Modules are similar to Layered systems in that each subsystem has clearly
defined tasks and interfaces, but any module is free to contact any other
module, eliminating the problems of going through multiple intermediary layers
✓ The kernel is relatively small in this architecture, similar to microkernels, but
the kernel does not have to implement message passing since modules are free
to contact each other directly. Eg: Solaris, Linux and Mac OS X
✓ The Apple Mac OS X Operating system uses a hybrid structure. It is a layered
system in which one layer consists of the Mach microkernel.
Traditional Computing
• Consider the “typical office environment.” Just a few years ago, this environment
consisted of PCs connected to a network, with servers providing file and print
services.
• Terminals attached to mainframes were prevalent at many companies as well, with
even fewer remote access and portability options.
• Web technologies and increasing WAN bandwidth are stretching the boundaries of
traditional computing. Companies establish portals, which provide Web
accessibility to their internal servers. Network computers (or thin clients)—which
are essentially terminals that understand web-based computing—are used in place
of traditional workstations where more security or easier maintenance is desired.
• At home, most users once had a single computer with a slow modem connection to
the office, the Internet, or both.
• Many homes use firewalls to protect their networks from security breaches.
School of C&IT
REVA University, Bengaluru Page 12
OPERATING SYSTEMS
Mobile Computing
Distributed Systems
Client-Server Computing
• As PCs have become faster, more powerful, and cheaper, designers have shifted
away from centralized system architecture.
• Figure 11 depicts the General structure of a client–server system.
• Many of today’s systems act as server systems to satisfy requests generated by
client systems.
• Server systems can be broadly categorized as compute servers and file servers:
• The 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 the results to the client.
• The file-server system provides a file-system interface where clients can create,
update, read, and delete files.
Peer-to-Peer Computing
• Another structure for a distributed system is the peer-to-peer (P2P) system model.
• In this model, clients and servers are not distinguished from one another.
• Instead, all nodes within the system are considered peers, and each may act as
either a client or a server, depending on whether it is requesting or providing a
service.
• Peer-to-peer systems offer an advantage over traditional client-server systems.
• To participate in a peer-to-peer system, a node must first join the network of peers.
Once a node has joined the network, it can begin providing services to—and
requesting services from—other nodes in the network.
• Determining what services are available is accomplished in one of two general ways:
✓ 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. The
remainder of the communication takes place between the client and the service
provider.
✓ An alternative scheme uses no centralized lookup service. Instead, a peer acting
as a client must discover what node provides a desired service by broadcasting a
request for the service to all other nodes in the network as shown in figure 12.
School of C&IT
REVA University, Bengaluru Page 14
OPERATING SYSTEMS
Virtualization
Cloud Computing
• Cloud computing is a type of computing that delivers computing, storage, and even
applications as a service across a network. In some ways, it’s a logical extension of
virtualization, because it uses virtualization as a base for its functionality.
• There are three types of cloud computing:
✓ Public cloud—a cloud available via the Internet to anyone willing to pay for the
services.
✓ Private cloud—a cloud run by a company for that company’s own use.
✓ Hybrid cloud—a cloud that includes both public and private cloud components.
✓ Software as a service (SaaS)—one or more applications (such as word processors
or spreadsheets) available via the Internet
✓ Platform as a service (PaaS)—a software stack ready for application use via the
Internet (for example, a database server)
School of C&IT
REVA University, Bengaluru Page 15
OPERATING SYSTEMS
School of C&IT
REVA University, Bengaluru Page 16
OPERATING SYSTEMS
• User Interface: Means by which users can issue commands to the system.
Depending on the operating system these may be a command-line interface (CLI),
a Graphical User Interface (GUI) or a Batch Command Interface.
In Command Line Interface(CLI)- commands are given to the system. In Batch
interface-commands and directives to control these commands are entered in a
file and then the file is executed. In GUI systems- windows with pointing device
to get inputs and keyboard to enter the text.
• Program Execution: The OS must be able to load a program into memory, run
the program, and terminate the program, either normally or abnormally.
• I/O Operations: The OS is responsible for transferring the data to and from I/O
devices, including keyboards, terminals, printers, and files. For specific devices,
special functions (device drivers) are provided by OS.
• File-System Manipulation: Programs need to read and write files or directories.
The services required to create or delete files, search for a file, list the contents
of a file and change the file permissions are provided by OS.
• Communications: Communication may occur when one process needs to
exchange information with another process. Such communication between the
processes may takes place on the same computer or between processes that are
executing on different computer systems. Communication may be implemented
by OS via shared memory or through message passing.
• Error Detection: Both hardware and software errors must be detected and
handled appropriately by the OS. Errors may occur in the CPU and memory
hardware (such as power failure and memory error), 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).
✓ OS also provide services (functions) for the efficient operation of the system, which
includes:
• Resource Allocation: Resources like CPU cycles, main memory, storage space,
and I/O devices must be allocated to multiple users and multiple jobs at the
same time. The OS provide CPU-scheduling routines that take into account the
speed of the CPU, the jobs that must be executed, the number of registers
available etc.
• Accounting: There are services in OS to keep track of system activity and
resource usage, either for billing purposes or for statistical record keeping that
can be used to optimize future performance.
• Protection and Security: The owners of information (file) in multiuser or
networked computer system may want to control the use of that information.
When several separate processes execute concurrently, one process should not
interfere with other or with OS.
School of C&IT
REVA University, Bengaluru Page 17
OPERATING SYSTEMS
• System calls provide an interface to access the services of the operating system.
• Generally written in C or C++, although some are written in assembly-language for
optimal performance.
• The below figure 14 illustrates the sequence of system calls required to copy a file
content from one file(input file) to another file (output file).
• For this, the program need names of two files: input file and output file. These
names can be provided in many ways.
• One approach: In interactive system, a sequence of system calls are required. First,
to write a message on the screen and then to accept the input filename from
keyboard
• Second approach: In mouse-based and icon-based systems, a menu of filenames is
displayed on the screen. Then the user can use the mouse to select the source name
and the destination name
• When the program tries to open the input file, it may find that there is no file of that
name or that the file is protected against access. In these cases, the program should
print a message on the console(another system call) and then terminate abnormally
(another system call).
• If input file exists, then create a new output file (another system call). In this
situation, we may find that there is already an output file with the same name,
School of C&IT
REVA University, Bengaluru Page 18
OPERATING SYSTEMS
which cause the program to abort (a system call), or may delete the existing file
(another system call) and create a new one (another system call)
• Now that both the files are opened, we enter a loop that reads from the input
file(another system call) and writes to output file (another system call).
• Finally, after the entire file is copied, the program may close both files (another
system call), write a message to the console or window(system call), and finally
terminate normally (final system call).
• Most programmers do not use the low-level system calls directly, but instead use an
"Application Programming Interface", API.
• The API specifies a set of functions that are available to an application programmer,
including the parameters that are passed to each function and the return values the
programmer can expect.
• The APIs instead of direct system calls provides for greater program portability
between different systems. The API then makes the appropriate system calls
through the system call interface, using a system call table to access specific
numbered system calls, as shown in Figure 15.
• Typically, a number is associated with each system call, and the system-call
interface maintains a table indexed according to these numbers.
• The system call table (consisting of system call number and address of the
particular service) invokes a particular service routine for a specific system call.
• The caller need know nothing about how the system call is implemented or what it
does during execution.
Figure 15: The handling of a user application invoking the open( ) system call
School of C&IT
REVA University, Bengaluru Page 19
OPERATING SYSTEMS
• Parameters can be pushed onto the stack by program and popped off the stack
by OS.
✓ Some OS prefer the block or stack method because those approaches do not limit
the number or length of parameters being used.
• System calls can be grouped roughly into six major categories: process control, file
manipulation, device manipulation, information maintenance,
communications, and protection.
Process Control
• A running program needs to be able to halt its execution either normally (end()) or
abnormally (abort()). If a system call is made to terminate the currently running
program abnormally, or if the program runs into a problem and causes an error
trap, a dump of memory is sometimes taken and an error message generated.
• A process or job executing one program may want to load() and execute() another
program.
• If both programs continue concurrently, we have created a new job or process to be
multiprogrammed. Often, there is a system call specifically for this purpose
(create_process() or submit_job()).
• If we create a new job or process, or perhaps even a set of jobs or processes, we
should be able to control its execution. This control requires the ability to determine
and reset the attributes of a job or process, including the job’s priority, its
maximum allowable execution time, and so on (get_process _attributes() and
set_process_attributes()).
• Having created new jobs or processes, we may need to wait for them to finish their
execution. We may want to wait for a certain amount of time to pass (wait_time()).
• More probably, we will want to wait for a specific event to occur (wait_event()). The
jobs or processes should then signal when that event has occurred (signal_event()).
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.
School of C&IT
REVA University, Bengaluru Page 20
OPERATING SYSTEMS
• Once the file is created, we need to open() it and to use it. We may also read(),
write(), or reposition() (rewind or skip to the end of the file, for example). Finally,
we need to close() the file, indicating that we are no longer using it.
• File attributes include the file name, file type, protection codes, accounting
information, and so on. At least two system calls, get_file_attributes() and
set_file_attributes(), are required for this function.
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.
• The various resources controlled by the operating system can be thought of as
devices. Some of these devices are physical devices (for example, disk drives), while
others can be thought of as abstract or virtual devices (for example, files).
• A system with multiple users may require us to first request() a device, to ensure
exclusive use of it. After we are finished with the device, we release() it. These
functions are similar to the open() and close() system calls for 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.
Information Maintenance
• Many system calls exist simply for the purpose of transferring information between
the user program and the operating system. 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 operating system, the amount of free
memory or disk space, and so on.
• Many operating systems provide a time profile of a program to indicate the amount
of time that the program executes at a particular location or set of locations.
• In addition, the operating system 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 (get_process_attributes() and
set_process_attributes())
Communication
• 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.
• Messages can be exchanged between the processes either directly or indirectly
through a common mailbox.
• Each process has a process name, and this name is translated into an identifier by
which the operating system can refer to the process.
School of C&IT
REVA University, Bengaluru Page 21
OPERATING SYSTEMS
• The get hostid() and get processid() system calls do this translation. The identifiers
are then passed to the general purpose open() and close() calls provided by the file
system or to specific open_connection() and close_connection() system calls,
depending on the system’s model of communication.
Protection
✓ File Management: These programs create, delete, copy, rename, print &
manipulate files and directories
✓ Status Information: Utilities to check on the date, time, number of users,
processes running, data logging, etc. System registries are used to store and
recall configuration information for particular applications.
✓ File Modification: Text editors are available to create and modify the contents
of file stored on disk. Special commands can also be used to search contents of
files or perform text manipulation on files
✓ Programming-Language Support: Compliers, assemblers & interpreters are
provided to the user with the OS
✓ Program loading and Execution: Once a program is assembled or compiled, it
must be loaded into memory to be executed. The OS provide absolute loaders,
relocatable loaders, linkage editors, overlay loaders etc .
✓ Communications: Programs provide the mechanism for creating virtual
connections among processors, users, and computer systems. It also includes
sending electronic mail messages, to browse web page, remote logins, file
transfers, and remote command execution.
✓ Application Programs: Most OS provide programs that are useful to solve
common problems or to perform common operations. Ex: web browsers, word
processors & text formatters etc.
• There are several ways for users to interface with the operating system.
• One provides a command-line interface, or command interpreter, that allows users
to directly enter commands to be performed by the operating system.
• The other allows users to interface with the operating system via a graphical user
interface, or GUI.
Command Interpreters
• Some operating systems include the command interpreter in the kernel. Others,
such as Windows and UNIX, treat the command interpreter as a special program
that is running when a job is initiated or when a user first logs on (on interactive
systems).
• On systems with multiple command interpreters to choose from, the interpreters are
known as shells.
School of C&IT
REVA University, Bengaluru Page 23
OPERATING SYSTEMS
• The main function of the command interpreter is to get and execute the next user-
specified command. Many of the commands given at this level manipulate files:
create, delete, list, print, copy, execute, and so on. The MS-DOS and UNIX shells
operate in this way.
• These commands can be implemented in two general ways.
✓ In one approach, the command interpreter itself contains the code to execute
the command.
✓ An alternative approach—used by UNIX, among other operating systems—
implements most commands through system programs.
• A second strategy for interfacing with the operating system is through a user-
friendly graphical user interface, or GUI.
• Here, rather than entering commands directly via a command-line interface, users
employ a mouse-based window and- menu system characterized by a desktop
metaphor.
• The user moves the mouse to position its pointer on images, or icons, on the screen
(the desktop) that represent programs, files, directories, and system functions.
• Depending on the mouse pointer’s location, clicking a button on the mouse can
invoke a program, select a file or directory—known as a folder—or pull down a
menu that contains commands.
• Graphical user interfaces first appeared due in part to research taking place in the
early 1970s at Xerox PARC research facility. The first GUI appeared on the Xerox
Alto computer in 1973.
• Because a mouse is impractical for most mobile systems, smartphones and
handheld tablet computers typically use a touchscreen interface. Here, users
interact by making gestures on the touchscreen—for example, pressing and swiping
fingers across the screen.
School of C&IT
REVA University, Bengaluru Page 24