Operating System:: Franz Vallerie B. Bueno BS Computer Engineering 4-2d
Operating System:: Franz Vallerie B. Bueno BS Computer Engineering 4-2d
Bueno
BS Computer Engineering 4-2d
Operating System:
An operating system is an essential component of a computer system. The primary objective of an operating system
is to make computer system convenient to use and utilize computer hardware in an efficient manner.
An operating system is a large collection of software, which manages resources of the computer system, such as
memory, processor, file system and input/output devices. It keeps track of the status of each resource and decides
who will have a control over computer resources, for how long and when. The positioning of operating system in
overall computer system is shown in figure 1.
From the figure, it is clear that operating system directly controls computer hardware resources. Other programs rely
on facilities provided by the operating system to gain access to computer system resources. Here are two ways one
can interact with operating system
Serial Processing:
Programming in 1s and 0s (machine language) was quite common for early computer systems. Instruction and data
used to be fed into the computer by means of console switches or perhaps through a hexadecimal keyboard.
Programs used to be started by loading the program counter register (a register which keeps track of which
instruction of a program is being executed) with the address of the first instruction of a program and its result
(program) used to be examined by the contents of various registers and memory locations of the machine. Therefore,
programming in this style caused a low utilization of both users and machine.
Advent of input/output devices, such as punched cards paper tapes and language translators
(Compiler/Assemblers) brought a significant step in computer system utilization. Program, being coded into
programming language, is first changed into object code (binary code) by translator and then automatically gets
loaded into memory by a program called loader. After transferring a control to the loaded program, the execution of
a program begins and its result gets displayed or printed. Once in memory, the program may be re-run with a
different set of input data.
The Process of development and preparation of a program in such environment is slow and cumbersome due to
serial processing and numerous manual processing. In a typical sequence first the editor is called to create a source
code of user program written in programming language, translator is called to convert a source code into binary code
and then finally loader is called to load executable program into main memory for execution. If syntax errors are
detected, the whole process must be restarted from the beginning.
The next development was the replacement of card-decks with standard input/output and some useful library
programs, which were further linked with user program through system software called linker. While there was a
definite improvement over machine language approach, the serial mode of operation is obviously not very efficient.
This results in low utilization of resources.
Batch Processing:
Utilization of computer resources and improvement in programmer's productivity was still a major prohibition.
During the time that tapes were being mounted or programmer was operating the console, the CPU was sitting idle.
The next logical step in the evolution of operating system was to automate the sequencing of operations involved in
program execution and in the mechanical aspects of program development. Jobs with similar requirements- were
batched together and run through the computer as a group. For example, suppose the operator received one
FORTRAN program, one COBOL program and another FORTRAN program. If he runs them in that order, he
would have to set up for FORTRAN program environment (loading the FORTRAN compiler tapes) then set up
COBOL program and finally FORTRAN program again. If he runs the two FORTRAN programs as a -batch,
however he could set up only once for FORTRAN, thus, saving operator's time.
Batching similar jobs brought utilization of system resources quite a bit. But there were still problems. For example,
when a job is stopped, the operator would have to notice that fact by observing the console, determine why the
program stopped and then load the card reader or paper tape reader with the next job and restart the computer.
During this transition from one job to the next, the CPU sat idle.
To overcome this idle time, a small program called a resident monitor was created which is always resident in the
memory. It automatically sequenced one job to another job. Resident monitor acts according to the directives given
by a programmer through control cards which contain information like marking of job's beginnings and endings,
commands for loading and executing programs, etc. These commands belong to job control language. These job
control language commands are included with user program and data. Here is an example of job control language
commands.
$COB - Execute the COBOL compiler
$JOB - First card of a job
$END - Last card of a job
$LOAD - Load program into memory
$RUN - Execute the user program
Figure 2: Card deck for Cobol Program for a simple batch system
With sequencing of program execution mostly automated by batch operating system, the speed discrepancy between
fast CPU and comparatively slow input/output devices such as card readers, printers emerged as a major
performance bottleneck. Even a slow CPU works in the microsecond range, with millions of instructions per-second.
But, fast card reader, on the other hand, might read 1200 cards per minute. Thus, the difference in speed between the
CPU and its input/output devices may be three orders of magnitude or more.
The relative slowness of input/output devices can mean that CPU is often waiting for input/output. As an example,
an Assembler or Compiler may be able to process 300 or more cards per second. A fast card reader, on the other
hand, may be able to read only 1200 cards per minute. This means that assembling or compiling a 1200 card
program would require only 4 seconds of CPU time but 60 seconds to read. Thus, the CPU is idle for 56 out of 60
seconds or 93.3 per cent of the time. The resulting CPU utilization is only 6.7 per cent. The process is similar for
output operations. The problem is that while an input/output is occurring, the CPU is idle, waiting for the
input/output to complete; while the CPU-is executing. Input/output devices are idle.
Over the years, of course, improvements in technology resulted in faster input/output devices. But CPU speed
increased even faster. Therefore, the need was to increase the throughput and resource utilization by overlapping
input/output and processing operations. Channels, peripheral controllers and later dedicated input/output processors
brought a major improvement in this direction. DMA (Direct Memory Access) chip which directly transfers the
entire block of data from its own buffer to main memory without intervention by CPU was a major development.
While CPU is executing, DMA can transfer data between high-speed input/output devices and main memory. CPU
requires to be interrupted per block only by DMA. Apart from DMA, there are two other approaches to improving
system performance by overlapping input, output and processing. These are buffering and spooling.
Buffering is a method of overlapping input, output and processing of a single job. The idea is quite simple. After
data has been read and the CPU is about to start operating on it, the input device is instructed to begin the next input
immediately. The CPU and input device are then both busy. With luck, by the time that the CPU is ready for the
next data item, the input device will have finished reading it. The CPU can then begin processing the newly read
data, while the input device starts to read the following data. Similarly, this can be done for output. In this case, the
CPU creates data that is put into a buffer until an output device can accept it.
If the CPU is, on the average much faster than an input device, buffering will be of little use. If the CPU is always
faster, then it always finds an empty buffer and has to wait for the input device. For output, the CPU can proceed at
full speed until, eventually all system buffers are full then the CPU must wait for the output device. This situation
occurs with input/output bound jobs where- the amount of input/output relation to computation is very high. Since
the CPU is faster than the input/output device, the input/output device controls the speed of execution, not by the
speed of the CPU.
More sophisticated form of input/output buffering called SPOOLING, (simultaneous peripheral operation on line)
essentially use the disk as a very large buffer (figure 3) for reading and for storing output files.
Figure 3: Spooling
Buffering overlaps input, output and processing of a single job whereas Spooling allows CPU to overlap the input
of one job with the computation and output of other jobs. Therefore this approach is better than buffering. Even
in a simple system, the spooler may be reading the input of one job while printing the output of a different job.
Multiprogramming:
Buffering and spooling improve system performance by overlapping the input, output and computation of a single
job, but both of them have their limitations. A single user cannot always keep CPU or I/O devices busy at all times.
Multiprogramming offers a more efficient approach to increase system performance. In order to increase the
resource utilization, systems supporting multiprogramming approach allow more than one job (program) to utilize
CPU time at any moment. More number of programs competing for system resources, better will be resource
utilization. The idea is implemented as follows. The main memory of a system contains more than one program
(Figure 4).
Figure 4: Memory layout in multiprogramming environment
The operating system picks one of the programs and start executing. During execution process (program) 1 may
need some I/O operation to complete. In a sequential execution environment (Figure 5a), the CPU would sit idle. In
a multiprogramming system, (Figure 5b) operating system will simply switch over to the next process (program 2).
When that program needs to wait for some I/O operation, it switches over to Program 3 and so on. If there is no other new
program left in the main memory, the CPU will pass its control back to the previous programs.
Multiprogramming has traditionally been employed to increase the resource utilization of a computer system and to support
multiple simultaneously interactive users (terminals).
Compared to operating system which supports only sequential execution, multiprogramming system requires some
form of CPU and memory management strategies which is beyond the scope of this block.
Non-interactive environment: There are some difficulties with a batch system from the point of view of user. Batch
operating systems allow little or no interaction between users and executing programs. The time taken between job
submission and job completion in batch operating system is very high. Users have no control over intermediate
results of a program. This type of arrangement does not create flexibility in software development.
The second disadvantage with this approach is that programs must be debugged which means a programmer cannot
correct bugs the moment it occurs.
The term multitasking is described any system that runs or appears to run more than one application program one
time. An effective multitasking environment must provide many services both to the user and to the application
program it runs. The most important of these are resource management which divides the computers time, memory
and peripheral devices among competing tasks and interprocess communication, which lets tasking co-ordinate their
activities by exchanging information.
Real-time Systems
It is another form of operating system which is used in environments where a large number of events mostly external
to computer systems, must be accepted and processed in a short time or within certain deadlines. Examples of such
applications are flight control, real time simulations etc. Real time systems are also frequently used in military
application.
A primary objective of real-time system is to provide quick response times. User convenience and resource
utilization are of secondary concern to real-time system. In the real-time system each process is assigned a certain
level of priority according to the relative importance of the event processes. The processor is normally allocated to
the highest priority process among those, which are ready to execute. Higher priority process usually pre-empt
execution of lower priority processes. This form of scheduling called, priority based pre-emptive scheduling, is used
by a majority of real-time systems.
Some of typical characteristics of network operating systems which may be different from distributed operating
system (discussed in the next section) are the followings:
Each computer has its own private operating system instead of running part of a global system wide
operating system.
Each user normally works on his/her own system; using a different system requires some kind of remote
login, instead of having the operating system dynamically allocate processes to CPUs.
Users are typically aware of where each of their files are kept and must move) file from one system to
another with explicit file transfer commands instead of having file placement managed by the operating
system.
The system has little or no fault tolerance; if 5% of the personnel computers crash, only 5% of the users is out of
business.
Distributed operating systems have many aspects in common with centralized ones but they also differ in certain
ways. Distributed operating system, for example, often allow programs to run on several processors at the same
time, thus requiring more complex processor scheduling (scheduling refers to a set of policies and mechanisms built
into the operating systems that controls the order in which the work to be done is completed) algorithms in order to
achieve maximum utilization of CPU's time.
Fault-tolerance is another area in which distributed operating systems are different. Distributed systems are
considered to be more reliable than uniprocessor based system. They perform even if certain part of the hardware is
malfunctioning. This additional feature supported by distributed operating system has enormous implications for the
operating system.
Windows 3.1 was released in 1991. By then, Windows had gained in market share. Microsoft released Windows 95
in August 1995. It was so well marketed and in such high demand that people bought the operating system, even if
they didn't own a home computer. With each new release, from Windows 98 to Window 2000 to Windows XP,
Microsoft gained popularity. Today, almost every new personal computer comes preloaded with the Windows
operating system. Windows can be run on practically any brand of personal computers. It is estimated that 90
percent of personal computers run the Windows operating system. The remaining 10 percent run the Macintosh
operating system.
UNIX is a multi-user, multitasking operating system, and was designed to be a small, flexible system used by
computer programmers. Since UNIX was designed to be used by programmers, it is not considered to be very user-
friendly for the average person. However, graphical user interfaces have been developed for UNIX to help alleviate
the ease-of-use issue.
Linux is a UNIX variant that runs on several different hardware platforms. Linus Torvalds, a student at the
University of Helsinki in Finland, initially created it as a hobby. The kernel, at the heart of all Linux systems, is
developed and released under the General Public License (GNU), and its source code is freely available to everyone.
There are now hundreds of companies, organizations, and individuals that have released their own versions of
operating systems based on the Linux kernel.
Because of its functionality, adaptability, and robustness, Linux is able to compete against the Unix and Microsoft
operating systems. IBM, Hewlett-Packard, and other computer giants have embraced Linux and support its ongoing
development. More than a decade after its initial release, Linux is being adopted worldwide mainly as a server
platform. More and more people are starting to use Linux as a home and office desktop operating system. The
operating system can also be incorporated directly into microchips in a process called "embedding." Many
appliances and devices are now starting to use operating systems in this way.
I/O Structure:
Programmed I/O
1. Application program (process) calls an I/O system call and waits for the I/O to complete.
2. I/O system call routine calls the corresponding I/O function of the device driver.
3. Device driver fills the registers of the device controller and signal “start”
4. The device controller starts the I/O and CPU checks the flag register of the device controller periodically
(polling overhead).
5. After each unit I/O, the device controller sets the flag in its register.
6. CPU finds the flag and moves the data to/from the main memory from/to the controller’s buffer.
7. Repeat from 2, 3, or 4)1 to 6) until all data is transferred to/from the device.
o CPU is free from the polling. Thus, CPU can process another job while the device is working on 4) and 5).
However, in a high-speed device, such as disk, step 4) is fast and frequently interrupts the CPU. As a result,
the CPU must switch to the interrupt routines very frequently to move the data in the controller buffer to
main memory (switching overhead). Good for byte (or word)-based slower devices (e.g., keyboard, serial
port)
Direct Memory Access (DMA)
1. Application program (process) calls an I/O system call and waits for the I/O completion.
2. I/O system call routine calls the corresponding I/O function of the device driver with a destination (main
memory location).
3. Device driver fills the registers in the device controller and signal “start”
4. The device controller starts the I/O and the CPU is free from the polling.
5. After each unit I/O, the device controller (or DMA controller) moves the data to/from the main memory
from/to the controller’s buffer.
6. Repeat from 2, 3, or 4) and 5) until all data are transferred to/from the device.
7. Device controller generates an interrupt signal.
o Since the device controller accesses main memory frequently, CPU processes other jobs at a slower speed.
Good for block-based fast I/O devices (e.g., disk and tape, usually block size is 512, 1K, 2K, or 4K bytes).
Memory-Mapped I/O
Ranges of main memory addresses are directly mapped to separate device registers. So, I/O is main memory
access. To perform I/O, CPU reads or writes data in these specific memory locations. After the read/write, the
data keep flow through the system bus and duplicated in the device controller’s registers. Then, device performs
I/O and the data transferred to the controller’s registers are also duplicated in the main memory.
o Additional memory overhead. Good for very fast byte (word)-based devices (e.g., video display)
Storage Structures:
Storage-device hierarchy
Coherency and Consistency problem: multiple copies of data (see “Read/Write through on Figure 3)
o The problem is more complex in tightly-coupled systems
o The problem is much more complex in loosely-coupled systems
Hardware Protection:
Example 1. An application program is trying to write on OS kernel code in main memory.
Example 2. An application program is trying to write on another program in main memory.
Example 3. An application runs infinite loop and hold CPU time infinitely.
Example 4. An application program prints indefinitely long data repeatedly.
Solution: Modern computer systems attack this problem by using “dual-mode operation”. In dual-mode
systems, only OS can access I/O devices, memory, and CPU in its “monitor” mode. User’s process will never
be allowed to directly access system resources. Application programs access these resources through “system
calls” indirectly (c.f., OS needs hardware “mode bit” for this solution: 8088 does not have it, after 80486
support this bit and, as a result, Windows/NT and OS/2 support dual mode operation).
OS may needs CPU timer and two additional memory registers (base and limit)