You are on page 1of 13

Chapter 2

Operating System Structures


10 Hours
20 Marks

2.1 System Component Activities

Operating System can be created by using large number of smaller pieces.


Each piece should be accurate portion of the system and should be clearly
defined. Various system component activities are
- Process Management
- Main Memory Management
- File Management
- I/O system Management
- Secondary Storage Management

1.1.1 Process Management


Program is a passive entity. It is just a file stored on disk. It does nothing
unless its instructions are executed by processor (CPU). Program in execution is
called as process. Process runs instructions of the program one after another. So,
process is an active entity.
A process needs certain resources like processor time, memory, file, I/O
devices etc for completing its task. These resources are given to the process at the
time of creation or they get allocated at the time of execution of the process. When
the process terminates, operating system reclaims resources those are reusable.
A process is unit of work in a system. Such system consists of collection of
processes some of which are operating system processes (those execute operating
system code) and rests of them are user processes (those execute user code).
Operating system is responsible for following activities related to process
management.
- Creating and deleting user/system processes
- Suspending and resuming processes
- Providing mechanisms for process synchronization
- Providing mechanisms for process communication
- Providing mechanisms for deadlock handling

1.1.2 Main Memory Management


Main memory is central to the operation of modern computer system. It is
a large array of bytes or words each of which has address. Main memory
facilitates quick access of data shared by CPU and I/O devices.
Generally main memory is the only memory that is directly addressed and
accessed by processor. For accessing data from other devices like hard disk, the
data should be firstly transferred to main memory. Also, whenever CPU wants to
execute instructions of any program, those must be available in main memory.
For this, program is loaded into main memory for execution. When execution of a
program terminates, the memory space it was using is declared as available (or
free) for other upcoming programs.

2-1
For improving speed of computer’s response to its users, several programs
should be kept in memory at a time. To handle this situation various memory
management techniques can be used.
Operating system is responsible for following activities related to memory
management.
- Keeping track of which parts of memory are currently being used and
by whom
- Deciding which processes and data to move into and out of memory
- Allocating and de-allocating memory space as needed

1.1.3 File Management


Major function of operating system is to hide extra details of disks and
other devices from users and present nice, clean, abstract model of device-
independent file to them. Computers can store information on several different
types of physical media like magnetic disk, optical disk etc. Each of these media
has its own physical organization and its own characteristics like access speed,
capacity, data transfer rate, access methods etc. File management works to hide
all these details from the user.
A file is a collection of related information created by its creator. Generally
files represent programs (either in source form or in object form) and data. Data
files may contain numeric, alphabetic, alphanumeric or binary data. Files may be
of free-form nature (as plain-text files) or of rigidly formatted structure (as
database file). These files are normally organized into directories to make them
easier to use.
Operating system is responsible for following activities related to file
management.
- Creating and deleting files
- Creating and deleting directories to organize files
- Supporting primitives for manipulating files and directories
- Mapping files onto secondary storage
- Backing up files on stable (non-volatile) storage media

1.1.4 I/O System Management


All computers have physical devices for acquiring input and producing
output. Some of the major input/ output devices are keyboard, mouse, monitor,
printer, speaker, mike etc.
Main purpose of operating system is to hide the crucial details of hardware
from the user of computer system and manage these devices.
Operating system is responsible for following activities related to file
management.
- General device driver interface
- Driver for specific hardware devices

1.1.5 Secondary Storage Management


Main memory is too small to hold all the data and programs. Also its
contents are lost when power to it gets disconnected. So, secondary storage is
used for baking up the main memory. Secondary storage is used for storing all the
data of users/ system, all the programs (user/ system), all the files and so on.
Most of the modern computer systems majorly use disk as secondary
memory. Hence proper management of disk storage is of central importance of a
2-2
computer system. As secondary storage is used frequently, it must be used
efficiently.
Operating system is responsible for following activities related to
secondary storage management.
- Free space management
- Storage allocation
- Disk scheduling

2.2 Operating System Services

An operating system provides services to programs and users executing


various programs. The services may vary from one operating system to another.
But general services which are normally provided by almost all the operating
systems are discussed below (from 2.2.1 to 2.2.9).

2.2.1 User Interface


Almost all operating systems have user interface (UI). Some operating
systems provide command-line interface (CLI) and others provide graphical
user interface (GUI). CLI accepts input from keyboard in the form of text
commands whereas GUI accepts additional input through a pointing device like
mouse.

2.2.2 Program execution


Operating system must be able to load a program in main memory and
execute it. The program once put in execution should able to end its execution
either normally or abnormally (i.e. forceful termination of execution).

2.2.3 I/O operation


A running program may require input/output operation. User is not able to
control the input/output device directly. Operating system must provide services
regarding input/ output operations.

2.2.4 File system manipulation


Users or user programs need to read files, write files, create files, delete
files. Operating system must provide file manipulation services.

2.2.5 Communication
One process may need to exchange some information with another process.
The communicating processes may be either on the single machine or they may
be on different machines. Operating system must be able to provide
communication services.

2.2.6 Error Detection


Operating system must be aware of possible errors that may occur during
operation of computer system. Errors may be like invalid memory access,
connection failure of I/O devices, power failure, errors in I/O devices (like printer
out of paper), divide by zero operation, arithmetic overflow etc. Operating system
should be able to detect such and all the errors and take actions accordingly.

2-3
2.2.7 Resource Allocation
A computer system may get used by multiple users at a time. Also a
computer system may execute multiple jobs at a time. So, proper resource
allocation must be done to the multiple users or multiple jobs so that proper
resource utilization can be achieved. Various resources that should be managed
are CPU, main memory, files, I/O devices etc.

2.2.8 Accounting
Operating system may keep track of users using various resources. The
record keeping can be maintained regarding which users are using which
resources and for how much period. This statistics can be used for charging the
users (if required). The major use of this statistics is to reconfigure the system for
improving the overall performance the system.

2.2.9 Protection and security


Operating system must provide security to system resources, users’ data or
to the system itself by providing authentication to user. This authentication may
be in the form of user name and password for accessing various resources.
Protection ensures the controlled access to system resources.

2.3 System Call

System calls provide an interface to the services provided by operating


system. User programs communicate with operating system and requests services
through system calls.
System calls are generally available as routines written either in high level
languages like C, C++ or in assembly language (where hardware is to be accessed
directly). Sometimes the system calls are available in the form of Application
Programming Interfaces (APIs).
Consider a situation where user wants to write into a file. The first input
required from user is name of file in which data is to be written. For getting this
input from user, system should prompt the user to enter the filename (for
displaying this message on display device a system call is invoked). Then
filename will be accepted from user through keyboard (system call for reading
from keyboard gets invoked). Then the file should be opened (using system call).
If file does not exist, error should be displayed (using system call). Data typed by
user (through system call for reading from keyboard) is written to the file
(through system call for writing into file). Then file is closed (using system call for
closing file). By reading this situation we may come to know that whenever any
operation is performed in the computer system a series of system calls get
invoked.
System call interface works as link to the system calls provided by the
operating system. General structure an working of system call interface is shown
in figure 2.1. Generally a number is associated with each system call. System call
interface maintains an index of all the system calls in a form of a table. When a
user program wants to perform specific task, System call interface interprets the
system call required for performing that task and invokes that system call. It
then returns status of system call and return values (if any).

2-4
User application

System Call Status /


return values
User mode
System Call Interface
Kernel mode

-
-
//Implementation of
-
//system call
--
- --
- --
- --
- --
return;

Figure 2.1: System Call Interface

Three general methods are used to pass parameters to the operating


system (obviously to the system calls). Simplest approach is to pass the
parameters through registers as shown in figure 2.2.

Register

Abc

Load Register
System call 21 Code for
Use Abc
system call 21

User Program

Operating System

Figure 2.2: Passing parameter through register

2-5
Problem with the above approach is that there may be more parameters
than the available registers. In such case, parameters are stored in a block of
memory and address of this block is passed as parameter in the register. This
approach is used by Linux and Solaris.
In the third method, parameters are pushed onto stack by the user
program and they are popped by the code of system call.

2.4 Types of System Call

System calls can be roughly grouped in to five categories as process control,


file manipulation, device management, information maintenance and
communication.

2.4.1 Process Control System Calls


System calls related to process control are as follows.
- 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
As already discussed, process is nothing but program in execution. Process
must be able to halt/ stop its execution either normally (end system call) or
abnormally (abort system call).
A process of job executing one program may want to load or execute
another program. The best example of such situation is command interpreter.
Command interpreter is a process which is running. When user types a command
on the command prompt, another program gets loaded and execution of this new
process starts. In such situation when execution of command is over, the control
is returned to the command interpreter.
But sometimes new process is to be executed in parallel with the current
process. In such cases the new process is to be created by using create process
system call.
When we create new jobs or processes, we should be able to control their
execution. For controlling their execution we should be able to determine (get
process attributes system call) and set (set process attributes system call)
attributes of job or process like priority, maximum allowable execution time and
so on. We may also want to terminate (terminate system call) job or process
which we have created.
When we have created a new process, we may want to wait for certain
amount of time (wait time system call). We may wait for specific event to occur
(wait event system call). When an event has occurred, it should be signaled
(signal event system call).
When a new process is created memory should be allocated to it (allocate
memory system call) and when a process gets terminated, the memory allocated
to it must be de-allocated (free memory system call).

2.4.2 File Manipulation System Calls


System calls related to file manipulation are
2-6
- create file, delete file
- open, close
- read, write, reposition
- get file attributes, set file attributes
We must be able to create file and delete file. Both these system calls
expect filename as parameter. Once a file is created, we should be able to open
file for using it. We may read, write and reposition (rewinding, skipping some
records, going to end of file etc) in the file. When we are no longer using the file
we should close file. Some of the above system calls may be used for directories
also.
In addition, some attributes of files or directories may need to be
determined (get file attributes system call) or set (set file attributes system
call). The attributes include file name, file type, size of file, access rights and so
on.

2.4.3 Device Management System Calls


System calls related to device management are
- request device, release device
- read, write, reposition
- get device attributes, set device attributes
- logically attach, detach devices
A process needs several resources for its execution. These resources may
include main memory hard disk, input output devices and so on. These resources
are considered as devices. Some devices are physical (as scanner) and some are
virtual (as a file).
If there are multiple users of the system or there are multiple processes in
the system, system may require us to first request device to ensure exclusive
use of it. After finishing use of the device we may release device so that other
users / processes may get that device.
Once the device has been allocated to us, we can perform various
operations like read, write and reposition on it. There is very much similarity
between files and devices. So, operating systems like UNIX merge files and
devices into combined file-device structure.
We may need to determine (get device attributes system call) or set (set
device attributes system call) the attributes of devices. Attributes may be like
left-handed or right-handed mouse, DPI of printer, read-only devices etc.
There may be need of logically attaching (attach system call) or detaching
(detach system call) the devices to the system.

2.4.4 Information Maintenance System Calls


System calls related to information maintenance are
- get time or date, set time or date
- get system data, set system data
- get process, file, device attributes
- set process, file, device attributes
There are many system calls that simply transfer information between
user program and the operating system. Most of the systems have system calls for
setting (set date, set time) and returning (get date, get time) system date and
time.

2-7
Some system calls are there for returning (get system data system call) or
setting (set system data system call) some system information like number of
users currently using the system, version number of operating system, amount of
free memory or disk, details of current process in the system and so on.
Additionally all the information related to processes, files and devices need
to be determined or set. For that purpose system calls are available.

2.4.5 Communication System Calls


System calls related to communication are
- create, delete communication connection
- send, receive messages
- transfer status information
- attach or detach remote devices
- create memory, shared memory attach
There are two common models of inter-process communication. They are
message passing model and shared memory model.
In message passing model, communication takes place through message
passing. Before communication can take place, a connection must be established
(create communication connection system call). Then send message and
receive message system calls may be used for sending and receiving messages
between two communicating processes. The communicating processes may be
either on the same computer or on different computers. If the communicating
processes are on different computers, remote device may be needed to be attached
(attach remote device system call) and detached (detach remote device
system call). Also there is need of transferring the status information of the
communicating processes to each other (transfer status information system
call). After completion of the communication, the communication connection may
be deleted (delete communication connection system call).
Normally operating system is designed in such a way that no any process
can get access to the memory of another process. But in case of shared memory
model of inter-process communication this restriction is needed to be removed.
For this purpose there are create memory system call and shared memory
attach system calls so that two communicating processes can communicate using
this shared memory.

2.5 Operating System Structure

Operating system is system software which is responsible for providing


various services as discussed in this chapter. Also it contains various components.
As operating system is very large and complex, it should be designed very
carefully so that it can function properly and can also be modified easily. So,
rather than designing a whole single program, it should be designed in smaller
parts. Normally operating system is divided into two parts – kernel and other OS
routines (of which major one is user interface). The most important and essential
part of operating system is kernel. Kernel is heart of operating system. It
directly interacts with and controls the hardware.

2-8
Kernel

Other OS routines

Application Programs

Figure 2.2: Kernel in Operating System

Different operating system structures have been defined which decides size
and functionality of kernel and organization of different components of operating
system. Some of them are,
- Simple or Monolithic Structure
- Layered Structure
- Microkernel Structure

2.5.1 Simple (or Monolithic) Structure


It is the oldest technique used for designing operating systems. It does not
have well-defined structure. In this approach entire operating system runs as a
single program (monolithic means huge). Operating system is written as
collection of procedures which are linked together in a single large binary
program. So, any procedure can interact with any procedure without any major
restrictions. This makes the system difficult to understand.
For constructing actual object program of the operating system, all the
individual procedures are compiled first and then all of them are bound together
into a single executable file.
One such model is shown in following figure.

Main
procedure

Service
procedures

Utility
procedures

Figure 2.3: Simple structuring model for a molithic system

This structure has very few interfaces between application programs and
hardware. One more model of monolithic structure is shown in following figure.
2-9
Application Program Application Program Application Program User Mode

System Call Interface


Kernel Mode

Module 1 Module 2

Module 3 Module 4

Kernel
Modules

Hardware

Figure 2.4: Another model for a molithic system

Advantage
- As very less number of interfaces is available between application
programs and hardware, system provides good and secured performance.

Disadvantage
- It is difficult to maintain such system. Modification done in one module can
affect other module of the system.

Example
- MS DOS

2.5.2 Layered Structure


This approach overcomes the drawback of monolithic structure. Operating
system is broken into smaller and appropriate pieces. Modifications can be easily
done in such system. These modules are organized in hierarchy of layers. Lowest
layer is hardware. The layer just above it interacts with hardware. Topmost layer
is user interface.
The layers are selected such that each layer uses functions, operations and
services provided by only its lower layers. This approach simplifies debugging and
system verification. First layer can be directly debugged without consideration of
any of the above layer. When first layer is debugged, second layer can be
debugged by assuming correct functioning of first layer and so on. If any error is
found while debugging any layer, it is due to code in the same layer only. So
design and implementation of system becomes easy.

2-10
Layer 0 -
Hardware

Layer 1

...

Layer n - User
Interface

Figure 2.5: Layered Structure

Advantage
- Main advantage is simplicity of construction and debugging.

Disadvantages
- All the requests (even if it is a very small task) pass through multiple
layers before they reach to hardware. Each layer adds overhead to system
call.
- It is difficult to design the layers

Examples
- THE – OS for Dutch system
- MULTICS
- UNIX

2.5.3 Microkernel Structure


When layered approach is used, designers have a choice of putting layers in
kernel. If all the layers are put in kernel, any bug in any layer can affect the
system’s performance. As we add more features to the operating system, kernel
becomes too heavy and unmanageable. So, better idea is to put minimum and
essential functionalities in kernel. This can be achieved by removing all non-
essential parts from the kernel and implementing them as system programs and
user-level programs. This approach is called microkernel (kernel is very small)
approach.
Typically, microkernel provides minimal process management, memory
management and communication facility. Other functionalities are implemented
outside the kernel as system programs which are known as servers. The
application programs (user programs) communicate to these servers and
microkernel using message passing.

2-11
Application Program Application Program

User Mode
File Server Print Server Display Server

Microkernel Kernel Mode

Hardware

Figure 2.6: Microkernel Structure

Advantages
- Extending the operating system is easy as all the new services can be
added to outside the kernel (i.e. modifications to kernel are not required).
- As microkernel is not needed to be modified, such operating systems can be
portable to any hardware easily.
- As most of the services are running outside the kernel, even if any service
fails, it does not affect the kernel. Thus makes the operating system more
secure and reliable.

Disadvantage
- Extensive message passing may degrade the overall performance of the
system.

Examples
- Mach
- QNX

2.6 Booting

Booting is nothing but changing the state of computer from sleep state to
wakeup state. When computer is powered on or restarted, it does not have
operating system in random access memory (i.e. main memory). The computer
first executes a relatively small program stored in read-only memory (ROM or
EEPROM).
The small program that starts this sequence is known as a bootstrap
loader, bootstrap or boot loader. This small program's only job is to load other
data and programs which are then executed from RAM.
On receiving boot signal, some computer systems may load a very small
number of fixed instructions into memory at a specific location, initialize at least
one CPU, and then point the CPU to the instructions and start their execution.
These instructions typically start an input operation from some peripheral device.

2-12
Other systems may send hardware commands (such as "read sector zero of
the system device into memory starting at location 0F00") directly to peripheral
devices or I/O controllers that cause an extremely simple input operation to be
carried out (loading a small number of boot loader instructions into memory).
Then execution of the instructions starts by the CPU.
Kernel (heart of operating system) is located and loaded into memory.
Operating System starts executing first process such as ‘init’ and waits for
interrupts to occur (Now computer is ready).
Normal sequence of operation that is performed when computer boots is as
follows
1. Check CMOS (Complementary Metal Oxide Semiconductor) setup
2. Load interrupt handlers and device drivers
3. Initialize registers and power management
4. Perform POST (Power On Self Test)
5. Display System Settings
6. Determine bootable devices
7. Initiate the bootstrap sequence

2-13

You might also like