Os Notes New New
Os Notes New New
SYSTEM
CONCEPTS
ABRAHAM SILBERSCHATZ
Yale University
PETER BAER GALVIN
Pluribus Networks
GREG GAGNE
Westminster College
NINTH EDITION
Chapter 1 Introduction
A computer system can be divided roughly into four components: the hardware, the
operating system, the application programs, and the users (Figure 1.1).
The hardware—the central processing unit (CPU), the memory and the input/output
(I/O) devices—provides the basic computing resources for the system.
The operating system controls the hardware and coordinates its use among the various
application programs for the various users.
1.1.1 User View
The user’s view of the computer varies according to the interface being used. Most
computer users sit in front of a PC, consisting of a monitor, keyboard, mouse, and system
unit. Such a system is designed for one user to monopolize its resources. The goal is to
maximize the work that the user is performing.
The operating system is the program most intimately involved with the hardware. In
this context, we can view an operating system as a resource allocator. A computer system has
many resources that may be required to solve a problem: CPU time, memory space, file-
storage space, I/O devices, and so on. The operating system acts as the manager of these
resources. Facing numerous and possibly conflicting requests for resources, the operating
system must decide how to allocate them to specific programs and users so that it can operate
the computer system efficiently.
Operating system covers many roles and functions. Computers are present within
toasters, cars, ships, spacecraft, homes, and businesses. They are the basis for game
machines, music players, cable TV tuners, and industrial control systems.
The fundamental goal of computer systems is to execute user programs and to make
solving user problems easier. Computer hardware is constructed toward this goal. Since bare
hardware alone is not particularly easy to use, application programs are developed. These
programs require certain common operations, such as those controlling the I/O devices. The
common functions of controlling and allocating resources are then brought together into one
piece of software: the operating system.
Most computer systems used a single processor. 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.
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.
The multiple-processor systems in use today are of two types. Some systems use
asymmetric multiprocessing, in which each processor is assigned a specific task. A boss
processor controls the system; the other processors either look to the boss for instruction or
have predefined tasks. This scheme defines a boss–worker relationship. The boss processor
schedules and allocates work to the worker processors.
The most common systems use symmetric multiprocessing (SMP), in which each
processor performs all tasks within the operating system. SMP means that all processors are
peers; no boss–worker relationship exists between processors.
In symmetric clustering, two or more hosts are running applications and are
monitoring each other. This structure is obviously more efficient, as it uses all of the
available hardware. Since a cluster consists of several computer systems connected via a
network, clusters can also be used to provide high-performance computing environments.
Such systems can supply significantly greater computational power than single-processor or
even SMP systems because they can run an application concurrently on all computers in the
cluster.
.
One of the most important aspects of operating systems is the ability to multiprogram.
A single program cannot, keep either the CPU or the I/O devices busy at all times. Single
users frequently have multiple programs running.
When that job needs to wait, the CPU switches 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.
A program loaded into memory and executing is called a process. Time sharing and
multiprogramming require that several jobs be kept simultaneously in memory.
If several jobs are ready to be brought into memory, and if there is not enough room
for all of them, then the system must choose among them. Making this decision involves job
scheduling.
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.
A bit, called the mode bit, is added to the hardware of the computer to indicate the
current mode: kernel (0) or user (1). With the mode bit, we can distinguish between a task
that is executed on behalf of the operating system and one that is executed on behalf of the
user.
When the computer system is executing on behalf of a user application, the system is
in user mode. At system boot time, the hardware starts in kernel mode. The operating system
is then loaded and starts user applications in user mode.
Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel
mode. Thus, whenever the operating system gains control of the computer, it is in kernel
mode. The system always switches to user mode before passing control to a user program.
1.4.2 Timer
A timer can be set to interrupt the computer after a specified period. The period may
be fixed or variable. 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. For instance, a 10-bit counter
with a 1-millisecond clock allows interrupts at intervals from 1 millisecond to 1,024
milliseconds, in steps of 1 millisecond.
Multi-threaded process has one program counter per thread . Typically system
has many processes, some user, some operating system running concurrently
on one or more CPUs
The operating system is responsible for the following activities in connection with
process management:
Chapter 2
2.1 OS Services
One set of operating-system services provides functions that are helpful to the
user:
User interface :Almost all operating systems have a user interface (UI)
Program execution - The system must be able to load a program into memory
and to run that program, end execution, either normally or abnormally
(indicating error)
I/O operations - A running program may require I/O, which may involve a file
or an I/O device
File-system manipulation - The file system is of particular interest. Obviously,
programs need to read and write files and directories, create and delete them,
search them, list file Information, permission management.
One set of operating-system services provides functions that are helpful to the
user (Cont):
May occur in the CPU and memory hardware, in I/O devices, in user program
For each type of error, OS should take the appropriate action to ensure correct
and consistent computing
Debugging facilities can greatly enhance the user’s and programmer’s abilities
to efficiently use the system
Another set of OS functions exists for ensuring the efficient operation of the
system itself via resource sharing.
Many types of resources - Some (such as CPU cycles, main memory, and file
storage) may have special allocation code, others (such as I/O devices) may
have general request and release code.
Accounting - To keep track of which users use how much and what kinds of
computer resources .
1. Command Interpreters
Others, such asWindows 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.
For example, on UNIX and Linux systems, a user may choose among several
different shells, including the Bourne shell, C shell, Bourne-Again shell, Korn
shell, and others.
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.
the UNIX command to delete a file
rm file.txt
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.
A mouse is impractical for most mobile systems, smartphones and handheld tablet
computers typically use a touchscreen interface.
3 Choice of Interface
System administrators who manage computers and power users who have deep
knowledge of a system frequently use the command-line interface.
For them, it is more efficient, giving them faster access to the activities they need to
perform.
Most Windows users are happy to use the Windows GUI environment and almost
never use the MS-DOS shell interface.
The various changes undergone by the Macintosh operating systems provide a nice
study in contrast.
Mac OS has not provided a command-line interface, always requiring its users to
interface with the operating system using its GUI.
Three most common APIs are Win32 API for Windows, POSIX API for POSIX
based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and
Java API for the Java virtual machine (JVM) .
Example: System call sequence to copy the contents of one file to another file
The caller need know nothing about how the system call is implemented.
Just needs to obey API and understand what OS will do as a result call o Most details
of OS interface hidden from programmer by API.
Managed by run-time support library (set of functions built into libraries included
with compiler).
Process control
File management
Device management
Information maintenance
Communications
Protection
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
Information maintenance
Communications
Some of them are simply user interfaces to system calls. Others are considerably
more complex. They can be divided into these categories:
• 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, and PERL) are often provided with
the operating systemor available as a separate download.
• 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 e-mail messages, to log in remotely, or to
transfer files from one machine to another.
• Background services. All general-purpose systems have methods for launching certain
system-program processes at boot time. Some of these processes terminate after completing
their tasks, while others continue to run until the system is halted. Constantly running system-
program processes are known as services, subsystems.
1. Design Goals
At the highest level, the design of the system will be affected by the choice of
hardware and the type of system: batch, time sharing, single user, multiuser,
distributed, real time, or general purpose.
Users want certain obvious properties in a system. The system should be convenient
to use, easy to learn and to use, reliable, safe, and fast.
The system should be easy to design, implement, and maintain; and it should be
flexible, reliable, error free, and efficient. Again, these requirements are vague and
may be interpreted in various ways.
3. Implementation
Now, although some operating systems are still written in assembly language, most
are written in a higher-level language such as C or an even higher-level language such
as C++.
An operating system can be written in more than one language. The lowest levels of
the kernel might be assembly language. Higher-level routines might be in C, and
system programs might be in C or C++, in interpreted scripting languages like PERL
or Python, or in shell scripts.
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
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.
This program is in the form of read-only memory (ROM), because the RAM is in an
unknown state at system startup.
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.
Storing the operating system in ROM is suitable for small operating systems, simple
supporting hardware, and rugged operation.
A disk that has a boot partition is called a boot disk or system disk.
The full bootstrap program has been loaded, it can traverse the file system to find the
operating system kernel, load it into memory, and start its execution. This is said to
be running.