OS-Unit-1
OS-Unit-1
Unit – I
Prepared by:
JYOTI PRKASH MOHANTA
Asst. Prof. of Computer Science
F M Autonomous College, Balasore
A computer system can be divided roughly into four components: the hardware, the
operating system, the application programs and the users.
The operating system controls the hardware and coordinates its use among the
various application programs for the various users.
An operating system is similar to government; performs no useful function by itself.
It simply provides an environment within which other programs can do useful work.
From the computer’s point of view, we can see the 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.
An operating system is a control program. A control program manages the execution
of user programs to prevent errors and improper use of the computer.
It is especially concernedwith the operation and control of I/O devices.
A common definition of operating system is that: “the operating system is the one
program running at all times on the computer - usually called the kernel”.
2. Computer-System Organization
The CPU can load instructions only from memory, so any programs to run must be
stored there. This memory is called main memory (also called random-access
memory or RAM).
Ideally, we want the programs and data to reside in main memory permanently. This
arrangement usually is not possible for the following two reasons:
o Main memory is usually too small to store all needed programs and data.
o Main memory is a volatile that is it loses its contents when power is off.
Thus, most computer systems provide secondary storage as an extension of main
memory to store large quantities of data permanently.
The most common secondary-storage device is a magnetic disk, which provides
storage for both programs and data.
Other memory technologies include - cache memory, CD-ROM, magnetic tapes etc.
[Storage-device hierarchy]
3. Operating-System Structure
An operating system provides the environment within which programs are executed.
A single program cannot keep either the CPU or the I/O devices busy at all times.
This requires multiprogramming. Multiprogramming increases CPU utilization by
organizing jobs so that the CPU always has one job to execute.
Multiprogramming requires several jobs in main memory simultaneously. Since main
memory is too small to accommodate all jobs, the jobs are kept initially on the disk.
The operating system picks and begins to execute one of the jobs in memory. The
job may have to wait for some task, such as an I/O operation, to complete.
In a non-multiprogrammed system, the CPU would sit idle. In a multiprogrammed
system, the operating system simply switches to, and executes, another job. When
that job needs to wait, the CPU switches to another job, and so on.
Time sharing (or multitasking) is a logical extension of multiprogramming. In time-
sharing systems, the CPU executes multiple jobs by switching among them, but the
switches occur so frequently that the users can interact with each program while it is
running.
A time-shared operating system uses CPU scheduling and multiprogramming to
provide each user with a small portion of a time-shared computer.
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. This decision is called job scheduling.
Having several programs in memory at the same time requires some form of
memory management.
If several jobs are ready to run at the same time, the system must choose which job
will run first. This decision is called CPU scheduling.
4. Operating-System Operations
Modern operating systems are interrupt driven. Events are almost always signalled
by the occurrence of an interrupt or a trap. A trap (or an exception) is a software-
generated interrupt causedby an error.
For each type of interrupt, separate segments of code in the operating system
determine what action should be taken. An interrupt service routine is provided to
deal with the interrupt.
Since the operating system and the users share the hardware and software
resources of the computer system, we need to make sure that an error in a user
program should not affect other running program.
A properly designed operating system must ensure that an incorrect (or malicious)
program cannot cause other programs to execute incorrectly.
Dual-Mode of Operation
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.
So we need two separate modes of operation: user mode and kernel mode (also
called supervisor mode, system mode, or privileged mode).
A bit, called the mode bit, is added to the hardware of the computer to indicate the
current mode: kernel (0) or user (1).
The dual mode of operation provides us with the means for protecting the operating
system from errant users and errant users from one another.
This protection can be implemented by designating some of the machine
instructions that may cause harm as privileged instructions.
The hardware allows privileged instructions to be executed only in kernel mode.
If an attempt is made to execute a privileged instruction in user mode, the hardware
does not execute the instruction but rather treats it as illegal and traps it to the
operating system.
The instruction to switch to kernel mode is an example of a privileged instruction.
Some other examples include I/O control, timer management, and interrupt
management.
5. Process Management
A program does nothing unless its instructions are executed by a CPU. So a program
in execution is a process.
A process needs certain resources - including CPU time, memory, files,and I/O
devices - to accomplish its task.
These resources are either given to the process when it is created or allocated to it
while it is running.
Process is the unit of work in a system.
A system consists of a collection of processes, some of which are operating-system
processes (those that execute operating system code) and the rest of which are user
processes.
The operating system is responsible for the following activities in connection with
process management:
6. Memory Management
Main memory is a repository of quickly accessible data shared by the CPU and I/O
devices.
The CPU reads instructions from main memory during the instruction-fetch cycle
and both reads and writes data from main memory during the data-fetch cycle.
To improve both the utilization of the CPU and the speed of the computer’s response
to its users, general-purpose computers must keep several programs in memory,
creating a need for memory management.
The operating system is responsible for the following activities in connection with
memory management:
o Keeping track of which parts of memory are currently being used and who is
using them
o Deciding which processes (or parts of processes) and data to move into and out
of memory
o Allocating and de-allocating memory space as needed
7. Storage Management
File-System Management
A file is a collection of related information defined by its creator. Data files maybe
numeric, alphabetic, alphanumeric or binary.
The operating system implements the abstract concept of a file by managing mass-
storage media, such as tapes and disks and the devices that control them.
When multiple users have access to files, it may be desirable to control which user
may access a file and how that user may access it (for example, read, write, append).
The operating system is responsible for the following activities in connectionwith file
management:
Mass-Storage Management
Because the main memory is too small to accommodateall data and programs, the
computer system must provide secondary storage to back up main memory.
Most modern computer systems use disks as the principal on-line storage medium
for both programs and data.
The operating system is responsible for the following activities in connection with
disk management:
o Free-space management
o Storage allocation
o Disk scheduling
If a computer system has multiple users and allows the concurrent execution of
multiple processes, then access to data must be regulated.
For that purpose mechanisms ensure that files, memory segments, CPU, and other
resources can be operated on by only those processes that have gained proper
authorization from the operating system.
Protection is any mechanism for controlling the access of processesor users to the
resources defined by a computer system.
A system can have adequate protection but still be prone to failure and allow
inappropriate access.
It is the job of security to defend a system from external and internal attacks.
Protection and security require the system to be able to distinguish among all its
users.
Most operating systems maintain a list of user names andassociated user identifiers
(user IDs).
In some circumstances, we wish to distinguish among sets of users rather than
individual users.
To accomplish this, we need to define a group name and the set of users belonging
to that group. Group functionality canbe implemented as a system-wide list of group
names and group identifiers.
System Structures
1. Operating system 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 following are the services provided by operating system to the users:
User interface:
Almost all operating systems have a user interface (UI). This interface can take
several forms.
One form is Command-line interface (CLI) which uses text commands and it provides
a way for entering them. For example - Command prompt in Windows and Terminal
for Linux environment.
Another form is Batch interface that receives files which contains commands and
executes one by one.
One more form is Graphical user interface (GUI). This is a window system with a
pointing device to direct I/O, choose from menus and make selections and a
keyboard to enter text.
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 resources like file or an I/O device.
For specific devices, special functions may be desired (such as recording to a CD or
DVD drive).
Therefore, the operating system must provide away to do I/O operation to the
running program.
File-system manipulation:
Operating system provides functionalities for create, open, read, write, close and
delete files.
Communications:
Error detection:
Errors may occur in the CPU and memory hardware, in I/O devices 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.
Resource allocation:
When there are multiple users or multiple jobs running at the same time, resources
must be allocated to each of them.
The operating system manages many different types of resources such as CPU cycles,
main memory, and file storage.
Accounting:
Operating system keeps track of which users use how much and what kinds of
computer resources.
Command Interpreters
On UNIX and Linux systems, there are several different command interpreters are
present and these are called shells. These include 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.
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
o rm file.txt
This would search for a file called rm, load the file into memory, and execute it with
the parameter file.txt.
Graphical User Interfaces
3. System Calls
System calls provide an interface to the services provided by an OS. These calls are
generally available as routines written in C, C++ and some may be using assembly-
language instructions.
Let’s first use an example to illustrate how system calls are used: A simple program
to read data from one file and copy them to another file.
Process control:
o end, abort
o load, execute
o create process, terminate process
o get process attributes, set process attributes
o wait for time
o wait event, signal event
o allocate and free memory
File management:
Device management:
Communications:
5. System Programs
Another aspect of a modern system is its collection of system programs. System
programs, also known as system utilities, provide a convenient environment for
program development and execution.
System programs provide basic functionalities to users so that they do not need to
write their own environment for program development (editors, compilers) and
program execution (shells).
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.
Typically, these programs format and print the output to the terminal or other
output devices or files or display it in a window of the GUI.
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:
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 Webpages,
to send e-mail messages, to log in remotely, or to transfer files fromone machine to
another.
Background services:
Design Goals:
Implementation:
Simple Structure:
Many operating systems do not have well-defined structures. Such systems started
as small, simple, and limited systems and then grew beyond their original scope.
MS-DOS operating system was developed using simple structure.
It was originally designed and implemented by few people who had no idea that it
would be so popular.
It was written to provide the most functionality in the least space, so it was not
divided carefully.
Layered Approach:
In layered approach the operating system is broken into a number of layers (levels).
The bottom layer (layer 0) is the hardware; the highest (layer N) is the user interface.
A typical operating-system layer (say layer M), consists of data structures and a set
of routines that can be invoked by higher-level layers.
Layer M, in turn, can invoke operations on lower-level layers.
The main advantage of the layered approach is simplicity of construction and
debugging.
The major difficulty with the layered approach involves appropriately defining the
various layers.
[A layered operating system]
Microkernels:
The best current methodology for operating-system design involves using loadable
kernel modules.
Here, the kernel has a set of core components and links in additional services via
modules, either at boot time or during run time.
This type of design is common in modern implementations of UNIX, such as Solaris,
Linux, and Mac OS X, as well as Windows.
The idea of the design is for the kernel to provide core services while other services
are implemented dynamically, as the kernel is running.