Professional Documents
Culture Documents
UNIT 1-Reg 2021feb 15 2023 (Repaired)
UNIT 1-Reg 2021feb 15 2023 (Repaired)
9. Structuring methods 18
2
Elements
Organization
Elements
At a top level, a computer consists of,
1. Processor
2. memory and
3. I/O components.
These components are interconnected in some fashion to achieve the main function
of the computer, which is to execute programs.
Thus, there are 4 main structural elements:
1. Processor
2. Main Memory
3. I/O modules
4. System bus
1. Processor:
a. It controls the operation of a computer and performs its data processing
functions.
b. When there is only one processor, it is referred to as Central Processing
Unit. (CPU).
2. Main Memory:
a. Stores data and programs.
b. It is volatile. ie, the contents of the memory are lost, when the computer is
shut down.
c. Also referred to as real memory or primary memory.
3. I/O modules:
a. Move data between the computer and external environment.
b. External environment consists of variety of devices including,
i. Secondary memory devices (eg.disks)
ii. Communication equipment & terminals
4. System bus:
a. Provides for communication among
i. Processors
ii. main memory and
iii. I/O modules.
3
Computer-system operation
Storage structure
I/O structure
Computer-system operation:
A modern general-purpose computer system consists of one or more CPUs and
a number of device controllers connected through a common bus that provides
access to shared memory (Figure 1.2).
Each device controller is in charge of a specific type of device (for example,
disk drives, audio devices, or video displays).
The CPU and the device controllers can execute in parallel, competing for
memory cycles.
Bootstrap program
System processes
Interrupt
Bootstrap program:
o For a computer to start running—for instance, when it is powered up or
rebooted—it needs to have an initial program to run.
o This initial program, or bootstrap program, tends to be simple.
5
System processes:
o Once the kernel is loaded and executing, it can start providing services to
the system and its users.
o Some services are provided outside of the kernel, by system programs that
are loaded into memory at boot time to become system processes, or
system daemons that run the entire time the kernel is running.
Interrupt:
o The occurrence of an event is usually signalled by an interrupt from either
the hardware or the software.
o Hardware may trigger an interrupt at any time by sending a signal to the
CPU, usually by way of the system bus.
o Software may trigger an interrupt by executing a special operation called a
system call (also called a monitor call).
Storage structure:
Main memory:
o General-purpose computers run most of their programs from rewritable
memory, called main memory (also called random-access memory, or
RAM).
DRAM:
o Main memory commonly is implemented in a semiconductor
technology called dynamic random-access memory (DRAM).
ROM:
o ROM cannot be changed, only static programs, such as the bootstrap
program are stored there.
EEPROM:
6
o Volatile storage loses its contents when the power to the device is
removed.
o In the absence of expensive battery and generator backup systems, data
must be written to non-volatile storage for safekeeping.
I/O structure:
Storage is only one of many types of I/O devices within a computer.
A general-purpose 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.
Depending on the controller, more than one device may be attached.
For instance, seven or more devices can be attached to the small computer-
systems interface (SCSI) controller.
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 provides the rest of the
operating system with a uniform interface to the device.
8
o When the transfer is complete, the DMA module sends an interrupt signal to
the processor.
o Thus, the processor is involved only at the beginning and end of the
transfer.
Figure 1.5 shows the interplay of all components of a computer system.
9
making it easier for the programmer and for application programs to access and use
those facilities and services.
Evolution of OS
Serial processing
Simple batch systems
Multiprogrammed batch systems
Time-sharing systems
Serial processing:
From the late 1940s to the mid-1950s.
Users have access to the computer in series.
The programmer interacted directly with the computer hardware;
There was no OS.
Input:
o Programs in machine code were loaded via the input device (e.g., a card
reader).
In case of error:
o If an error halted the program, the error condition was indicated by the
lights.
Output:
o If the program proceeded to a normal completion, the output appeared
on the printer.
Scheduling:
Most installations used a hardcopy sign-up sheet to reserve
computer time.
A user might sign up for an hour and finish in 45 minutes.
A user might not finish in the allotted time and forced to stop.
Setup time:
A considerable amount of time was spent just in setting up the program
to run.
Instead, the user submits the job on cards or tape to a computer operator, who
batches the jobs together sequentially and places the entire batch on an input
device, for use by the monitor.
Each program is constructed to branch back to the monitor when it completes
processing, at which point the monitor automatically begins loading the next
program.
2 views:
1. Monitor point of view
2. Processor point of view
o The rest of the monitor consists of utilities and common functions that are
loaded as subroutines to the user program.
o The monitor reads in jobs one at a time from the input device (typically a card
reader or magnetic tape drive).
o As it is read in, the current job is placed in the user program area, and control is
passed to this job.
14
o When the job is completed, it returns control to the monitor, which immediately
reads in the next job.
o The results of each job are sent to an output device, such as a printer, for
delivery to the user.
Memory protection:
- While the user program is executing, it must not alter the memory
area containing the monitor.
- If such an attempt is made, the processor hardware should detect an
error and transfer control to the monitor.
Timer:
- The timer is set at the beginning of each job.
- If the timer expires, the user program is stopped, and control returns
to the monitor.
15
Privileged instructions:
- Certain machine level instructions are designated privileged and can
be executed only by the monitor.
- If the processor encounters such an instruction while executing a
user program, an error occurs causing control to be transferred to the
monitor.
Interrupts:
- This feature gives the OS more flexibility in relinquishing control to
and regaining control from user programs.
2 modes:
1. User mode
2. Kernel mode
User mode:
- A user program executes in a user mode, in which certain areas of
memory are protected from the user’s use and in which certain
instructions may not be executed.
Kernel mode:
- The monitor executes in a system mode, or what has come to be
called kernel mode, in which privileged instructions may be
executed and in which protected areas of memory may be accessed.
It must then wait until that I/O instruction concludes before proceeding.
When one job needs to wait for I/O, the processor can switch to the other job,
which is likely not waiting for I/O ( Figure 2.5b ).
We might expand memory to hold three, four, or more programs and switch
among all of them ( Figure 2.5c ). The approach is known as
multiprogramming , or multitasking . It is the central theme of modern
operating systems.
Merit
The most notable additional feature is the hardware that supports I/O interrupts and
DMA (direct memory access).
Demerit:
Requires some form of memory management.
Requires an algorithm for scheduling.
17
Time-sharing systems:
Just as multiprogramming allows the processor to handle multiple batch jobs at
a time, multiprogramming can also be used to handle multiple interactive jobs.
In this latter case, the technique is referred to as time sharing , because
processor time is shared among multiple users.
In a time-sharing system, multiple users simultaneously access the system
through terminals, with the OS interleaving the execution of each user program
in a short burst or quantum of computation.
Both batch processing and time sharing use multiprogramming. The key
differences are listed in Table 2.3 .
18
Operating system-structure
OR
Structuring methods
An operating system provides the environment within which programs are
executed.
A common approach is to partition the task into small components, or modules,
rather than have one single system.
(the users)
Monolithic Structure
Layered Approach
a system is divided into separate, smaller components that have specific and
limited func- tionality.
All these components together comprise the kernel.
The advantage of this modular approach is that changes in one component
affect only that component.
layered approach,
o operating system is broken into a number of layers (levels).
o The bottom layer (layer 0) is the hardware;
o the highest (layer N) is the user interface.
o This layering structure is depicted in Figure 2.14.
o The main advantage of the layered approach is simplicity of
construction and debugging.
20
Microkernels
structures the operating system by removing all nonessential components
from the kernel and implementing them as user- level programs that
reside in separate address spaces.
The result is a smaller kernel.
Modules
loadable kernel modules (LKMs).
Here, the kernel has a set of core components and can link in
additional services via modules, either at boot time or during run time.
Hybrid Systems
combine different structures, resulting in hybrid systems that address
performance, security, and usability issues.
For example, Linux is monolithic, because having the operating system in
a single address space provides very efficient performance. However, it
also modular, so that new functionality can be dynamically added to the
kernel.
Kernel environment.
This environment, also known as Darwin, includes the Mach
microkernel and the BSD UNIX kernel.
Android
The Android operating system was designed by the Open Handset
Alliance (led primarily by Google) and was developed for Android
smartphones and tablet computers.
The structure of Android appears in Figure 2.18.
Android is similar to iOS in that it is a layered stack of software that
provides a rich set of frameworks supporting graphics, audio, and
hardware features.
These features, in turn, provide a platform for developing mobile
applications that run on a multitude of Android-enabled devices.
23
If several jobs are ready to run at the same time, the system must choose which job
will run first. Making this decision is CPU scheduling.
Swapping
In a time-sharing system, the operating system must ensure reasonable response
time.
This goal is sometimes accomplished through swapping, whereby processes are
swapped in and out of main memory to the disk.
Virtual, physical & logical memory
virtual memory, a technique that allows the execution of a process that is not
completely in memory.
25
OPERATING-SYSTEM SERVICES
An operating system provides an environment for the execution of programs.
It makes certain services available to programs and to the users of those pro-
grams.
User interface.
Almost all operating systems have a user interface (UI). This
interface can take several forms.
Graphical user interface (GUI).
• the interface is a window system with
• a mouse that serves as a pointing device to direct I/O,
choose from menus, and make selections and
• a keyboard to enter text.
touch-screen interface
• Mobile systems such as phones and tablets provide a touch-
screen interface, enabling users to slide their fingers across
the screen or press buttons on the screen to select choices.
command-line interface (CLI),
• uses text commands and a method for entering them
Program execution.
The system must be able to load a program into memory and to run
that program.
I/O operations.
26
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 two allow users to interface with the operating system
via a graphical user interface, or GUI.
Command Interpreters
Most operating systems, including Linux, UNIX, and Windows,
treat the com- mand interpreter as a special program that is running
when a process is initiated or when a user first logs on.
On systems with multiple command interpreters to choose from,
the interpreters are known as shells.
Figure 2.2 shows the Bourne-Again (or bash) shell command
interpreter being used on macOS.
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.
These commands can be implemented in two general ways.
o In one approach, the command interpreter itself contains
the code to execute the command.
o An alternative approach— used by UNIX, among other
operating systems implements most commands through
system programs.
Thus, the UNIX command to delete a file
rm file.txt
would search for a file called rm, load the file into memory, and execute it
with the parameter file.txt.
28
1. Introduction:
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++, may have
to be written using assembly-language instructions.
System call interface:
o For most programming languages, the run-time support system provides
a system call interface that serves as the link to system calls made
available by the operating system.
The relationship between an API, the system-call interface, and the operating
system is shown in Figure 2.6, which illustrates how the operating system handles a
user application invoking the open() system call.
1. Process control:
i. end, abort
ii. load, execute
iii. create process, terminate process
iv. get process attributes, set process attributes
v. wait for time
vi. wait event, signal event
A running program needs to be able to stop execution either normally using end( )
or abnormally using abort( ).
A process or job executing one program may want to load( ) and execute( ) another
program.
The system call specifically for creating a new job or process to be
multiprogrammed is create_process( ) or submit_job( ).
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( )).
We may terminate a job or process that we created (terminate process( )) if we find
that it is incorrect or is no longer needed.
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( )).
2. File manipulation:
i. create file, delete file
ii. open, close
iii. read, write, reposition
iv. get file attributes, set file attributes
3. Device manipulation:
i. request device, release device
ii. read, write, reposition
iii. get device attributes, set device attributes
iv. logically attach or detach devices
2. Information maintenance:
i. get time or date, set time or date
32
ii. get system data, set system data
iii. get process, file, or device attributes
iv. set process, file, or device attributes
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,
o the number of current users,
o the version number of the operating system,
o the amount of free memory or disk space, and so on.
Another set of system calls is helpful in debugging a program.
Many systems provide system calls to dump( ) memory. This provision is useful for
debugging.
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( )).
3. Communications:
i. create, delete communication connection
ii. send, receive messages
iii. transfer status information
iv. attach or detach remote devices
4. Protection:
Protection provides a mechanism for controlling access to the resources provided
by a computer system.
34
Typically, system calls providing protection include set_permission( ) and
get_permission( ), which manipulate the permission settings of resources such as
files and disks.
The allow_user( ) and deny_user( ) system calls specify whether particular users
can—or cannot—be allowed access to certain resources.
35
36
System Programs
Definition
Categories
1. Definition:
System programs provide a convenient environment for program development and
execution.
Also known as system utilities.
2. Categories:
File Management
Status Information
File Modification
Programming-language support
Program loading and execution
Communications
Background services
File management:
o File is a collection of related information.
o These programs,
a. create
b. delete
c. copy
d. rename
e. print
f. dump and list files and directories.
Status information:
o Information related to,
a. Date,
b. time,
c. amount of available memory or disk space
d. number of users or similar status information.
o Complex information like,
a. Performance
b. Logging
c. Debugging information
File modification:
Text editors may be available to create and modify the content of files
stored on disk or other storage devices.
Programming-language support:
37
Compilers, assemblers, debuggers and interpreters for common
programming languages like C, C++, Java are provided with OS or
available as a separate download.
Communications:
These programs create virtual connections among processes, users, and
different computer systems. (email, FTP, Remote log in).
It allow users to,
Send messages to other’s screen
Browse web pages
Send e-mail
Remote log-in
Transfer files
Background services:
All general-purpose systems have methods for launching certain system-
program processes at boot time.
Constantly running system-program processes are known as services,
subsystems, or daemons.
38
OPERATING-SYSTEM DESIGN AND IMPLEMENTATION
Design Goals
The first problem in designing a system is to define goals and
specifications.
The requirements can, however, be divided into two basic groups:
user goals – operating system should be convenient to use, easy to
learn, reliable, safe and fast
system goals – operating system should be easy to design,
implement, and maintain as well as flexible, reliable, error free and
efficient.
Mechanisms and Policies
One important principle is the separation of policy from mechanism.
Mechanisms determine how to do something;
policies determine what will be done.
Policy decisions are important for all resource allocation. Whenever
it is necessary to decide whether or not to allocate a resource, a
policy decision must be made.
Whenever the question is how rather than what, it is a mechanism
that must be determined.
Implementation
Once an operating system is designed, it must be implemented.
Because operating systems are collections of many programs,
written by many people over a long period of time, it is difficult to
make general statements about how they are implemented.
Early operating systems were written in assembly language.
Now, most are written in higher-level languages such as C or C++,
with small amount of the system written in assembly language
The advantages of using a higher-level language,
the code can be written faster, is more compact, and is easier
to understand and debug.
improvements in compiler technology will improve the
generated code for the entire operating system by simple
recompilation.
an operating system is far easier to port to other hardware
if it is written in a higher-level language.
39
The only possible disadvantages of implementing an operating
system in a higher-level language are reduced speed and increased
storage requirements.
40