Mod 1
Mod 1
• Setup time: A single program, called a job, could involve loading the
compiler plus the high-level language program (source program) into
memory, saving the compiled program (object program) and then loading
and linking together the object program and common functions. Each of
these steps could involve mounting or dismounting tapes or setting up card
decks. If an error occurred, the hapless user typically had to go back to the
beginning of the setup sequence. Thus, a considerable amount of time was
spent just in setting up the program to run. This mode of operation could be
termed serial processing, reflecting the fact that users have access to the
computer in series. Over time, various system software tools were
developed to attempt to make serial processing more efficient. These include
libraries of common functions, linkers, loaders, debuggers, and I/O driver
routines that were available as common software for all users.
The central idea behind the simple batch-processing scheme is the use of a
piece of software known as the monitor. With this type of OS, the user no
longer has direct access to the processor. 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. To understand how this scheme works, let us look
at it from two points of view: that of the monitor and that of the processor.
• Monitor point of view: The monitor controls the sequence of events. For
this to be so, much of the monitor must always be in main memory and
available for execution (Figure 2.3). That portion is referred to as the resident
monitor. The rest of the monitor consists of utilities and common functions
that are loaded as subroutines to the user program at the beginning of any
job that requires them. The monitor reads in jobs one at a time from the input
device (typically a card reader or magnetic tape drive). As it is read in, the
current job is placed in the user program area, and control is passed to this
job. When the job is completed, it returns control to the monitor, which
immediately reads in the next job. The results of each job are sent to an
output device, such as a printer, for delivery to the user.
Even with the automatic job sequencing provided by a simple batch OS, the
processor is often idle. The problem is that I/O devices are slow compared to
the processor. Figure 2.4 details a representative calculation. The calculation
concerns a program that processes a file of records and performs, on average,
100 machine instructions per record. In this example, the computer spends
over 96% of its time waiting for I/O devices to finish transferring data to and
from the file. Figure 2.5a illustrates this situation, where we have a single
program, referred to as uniprogramming. The processor spends a certain
amount of time executing, until it reaches an I/O instruction. It must then
wait until that I/O instruction concludes before proceeding.
The average resource utilization, throughput, and response times are shown
in the uniprogramming column of Table 2.2. Device-by-device utilization is
illustrated in Figure 2.6a. It is evident that there is gross underutilization for
all resources when averaged over the required 30-minute time period. Now
suppose that the jobs are run concurrently under a multiprogramming OS.
Because there is little resource contention between the jobs, all three can run
in nearly minimum time while coexisting with the others in the computer
(assuming that JOB2 and JOB3 are allotted enough processor time to keep
their input and output operations active). JOB1 will still require 5 minutes to
complete, but at the end of that time, JOB2 will be one-third finished and
JOB3 half finished. All three jobs will have finished within 15 minutes. The
improvement is evident when examining the multiprogramming column of
Table 2.2, obtained from the histogram shown in Figure 2.6b . As with a
simple batch system, a multiprogramming batch system must rely on certain
computer hardware features. The most notable additional feature that is
useful for multiprogramming is the hardware that supports I/O interrupts
and DMA (direct memory access). With interrupt-driven I/O or DMA, the
processor can issue an I/O command for one job and proceed with the
execution of another job while the I/O is carried out by the device controller.
When the I/O operation is complete, the processor is interrupted and control
is passed to an interrupt-handling program in the OS. The OS will then pass
control to another job.
Time-Sharing Systems
Types of RTOS:
OS 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. The specific services provided, of course, differ from one
operating system to another, but we can identify common classes. These
operating system services are provided for the convenience of the
programmer, to make the programming task easier. Figure 2.1 shows one
view of the various operating-system services and how they interrelate. 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).
This interface can take several forms. One is a command-line interface
(CLI), which uses text commands and a method for entering them (say,
a keyboard for typing in commands in a specific format with specific
options). Another is a batch interface, in which commands and
directives to control those commands are entered into files, and those
files are executed. Most commonly, a graphical user interface (GUI) is
used. Here, the interface is a window system with a pointing device to
direct I/O, choose from menus, and make selections and a keyboard to
enter text. Some systems provide two or all three of these variations.
• 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).
• 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 (such as recording to a CD or DVD drive or blanking
a display screen). For efficiency and protection, users usually cannot
control I/O devices directly. Therefore, the operating system must
provide a means to do I/O.
• File-system manipulation. The file system is of particular interest.
Obviously, programs need to read and write files and directories. They
also need to create and delete them by name, search for a given file,
and list file information. Finally, some operating systems include
permissions management to allow or deny access to files or directories
based on file ownership. Many operating systems provide a variety of
file systems, sometimes to allow personal choice and sometimes to
provide specific features or performance characteristics.
• Communications. There are many circumstances in which one process
needs to exchange information with another process. Such
communication may occur between processes that are executing on the
same computer or between processes that are executing on different
computer systems tied together by a computer network.
Communications may be implemented via shared memory, in which
two or more processes read and write to a shared section of memory,
or message passing, in which packets of information in predefined
formats are moved between processes by the operating system.
• Error detection. The operating system needs to be detecting and
correcting errors constantly. 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 disk, 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. Sometimes, it has no choice but to halt the
system. At other times, it might terminate an error-causing process or
return an error code to a process for the process to detect and possibly
correct.
Another set of operating system functions exists not for helping the
user but rather for ensuring the efficient operation of the system itself.
Systems with multiple users can gain efficiency by sharing the
computer resources among the users.
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++, although certain low-level tasks (for example, tasks where
hardware must be accessed directly) may have to be written using assembly-
language instructions.
writing a simple program to read data from one file and copy them to
another file. The first input that the program will need is the names of the
two files: the input file and the output file. These names can be specified in
many ways, depending on the operating-system design. One approach is for
the program to ask the user for the names. In an interactive system, this
approach will require a sequence of system calls, first to write a prompting
message on the screen and then to read from the keyboard the characters
that define the two files. On mouse-based and icon-based systems, a menu
of file names is usually displayed in a window. The user can then use the
mouse to select the source name, and a window can be opened for the
destination name to be specified. This sequence requires many I/O system
calls.
Once the two file names have been obtained, the program must open the
input file and create the output file. Each of these operations requires another
system call. Possible error conditions for each operation can require
additional system calls. When the program tries to open the input file, for
example, 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 sequence of system calls) and then terminate
abnormally (another system call). If the input file exists, then we must create
a new output file. We may find that there is already an output file with the
same name. This situation may cause the program to abort (a system call),
or we may delete the existing file (another system call) and create a new one
(yet another system call). Another option, in an interactive system, is to ask
the user (via a sequence of system calls to output the prompting message
and to read the response from the terminal) whether to replace the existing
file or to abort the program.
When both files are set up, we enter a loop that reads from the input file (a
system call) and writes to the output file (another system call). Each read and
write must return status information regarding various possible error
conditions. On input, the program may find that the end of the file has been
reached or that there was a hardware failure in the read (such as a parity
error). The write operation may encounter various errors, depending on the
output device (for example, no more disk space).
Finally, after the entire file is copied, the program may close both files
(another system call), write a message to the console or window (more
system calls), and finally terminate normally (the final system call). This
system-call sequence is shown in Figure 2.5.
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.
Three general methods are used to pass parameters to the operating system.
The simplest approach is to pass the parameters in registers. In some cases,
however, there may be more parameters than registers. In these cases, the
parameters are generally stored in a block, or table, in memory, and the
address of the block is passed as a parameter in a register (Figure 2.7). This
is the approach taken by Linux and Solaris. Parameters also can be placed,
or pushed, onto the stack by the program and popped off the stack by the
operating system. Some operating systems prefer the block or stack method
because those approaches do not limit the number or length of parameters
being passed.
• Process control
• File manipulation
• Device manipulation
• Information maintenance
• Communications
• Protection.
System Programs. System programs, also known as system utilities,
provide a convenient environment for program development and execution.
Some of them are simply user interfaces to system calls. Others are
considerably more complex. They can be divided into these categories: