OS Unit 1
OS Unit 1
UNIT I
INTRODUCTION
COMPUTER SYSTEM - ELEMENTS AND ORGANIZATION
Computer systems consist of three components as shown in below image: Central Processing
Unit, Input devices and Output devices. Input devices provide data input to processor, which
processes data and generates useful information that’s displayed to the user through output
devices. This is stored in computer’s memory.
IMPORTANT TERMS
Starting address of memory segment.
Effective address or Offset: An offset is determined by adding any combination of three
address elements: displacement, base and index.
Displacement: It is an 8 bit or 16 bit immediate value given in the instruction.
Base: Contents of base register, BX or BP.
Index: Content of index register SI or DI.
Implied mode:In implied addressing the operand is specified in the instruction itself. In
this mode the data is 8 bits or 16 bits long and data is the part of instruction.Zero address
instruction are designed with implied addressing mode.
Immediate addressing mode (symbol #):In this mode data is present in address field of
instruction .Designed like one address instruction format.
Note:Limitation in the immediate mode is that the range of constants are restricted by
size of address field.
Register mode: In register addressing the operand is placed in one of 8 bit or 16 bit
general purpose registers. The data is in the register that is specified by the instruction.
Here one register reference is required to access the data.
Register Indirect mode: In this addressing the operand’s offset is placed in any one of
the registers BX, BP, SI, DI as specified in the instruction. The effective address of the
data is in the base register or an index register that is specified by the instruction.
Here two register reference is required to access the data.
Auto Indexed (increment mode): Effective address of the operand is the contents of a
register specified in the instruction. After accessing the operand, the contents of this
register are automatically incremented to point to the next consecutive memory location.
(R1)+.
Here one register reference, one memory reference, and one ALU operation is required
to access the data.
Auto indexed (decrement mode): Effective address of the operand is the contents of a
register specified in the instruction. Before accessing the operand, the contents of this
register are automatically decremented to point to the previous consecutive memory
location. –(R1)
Here one register reference, one memory reference and one ALU operation is required to
access the data.
Auto decrement mode is the same as the auto-increment mode. Both can also be used to
implement a stack as push and pop. Auto increment and Auto-decrement modes are useful for
implementing “Last-In-First-Out” data structures.
Direct addressing/ Absolute addressing Mode (symbol [ ]): The operand’s offset is
given in the instruction as an 8 bit or 16 bit displacement element. In this addressing
mode, the 16-bit effective address of the data is part of the instruction.
Here only one memory reference operation is required to access the data.
Indirect addressing Mode (symbol @ or () ):In this mode address field of instruction
contains the address of effective address.Here two references are required.
1st reference to get an effective address.
2nd reference to access the data.
Indexed addressing mode: The operand’s offset is the sum of the content of an index
register SI or DI and an 8 bit or 16-bit displacement.
Based Indexed Addressing: The operand’s offset is sum of the content of a base register
BX or BP and an index register SI or DI.
Based on Transfer of control, addressing modes are:
PC relative addressing mode: PC relative addressing mode is used to implement
intra segment transfer of control, In this mode effective address is obtained by
adding displacement to PC.
EA= PC + Address field value
PC= PC + Relative value.
Base register addressing mode:Base register addressing mode is used to
implement inter segment transfer of control.In this mode effective address is
obtained by adding base register value to address field value.
EA= Base register + Address field value.
PC= Base register + Relative value.
Note:
1. PC relative and based register both addressing modes are suitable for
program relocation at runtime.
2. Based register addressing mode is best suitable to write position
independent codes.
OPERATING SYSTEM OVERVIEW
An Operating System can be defined as an interface between user and hardware. It is
responsible for the execution of all the processes, Resource Allocation, CPU management, File
Management and many other tasks.
The purpose of an operating system is to provide an environment in which a user can execute
programs in convenient and efficient manner.
An Operating System (OS) is an interface between a computer user and computer hardware. An
operating system is a software which performs all the basic tasks like file management, memory
management, process management, handling input and output, and controlling peripheral devices
such as disk drives and printers.
An operating system is software that enables applications to interact with a computer's hardware.
The software that contains the core components of the operating system is called the kernel.
The primary purposes of an Operating System are to enable applications (software’s) to interact
with a computer's hardware and to manage a system's hardware and software resources.
Some popular Operating Systems include Linux Operating System, Windows Operating System,
VMS, OS/400, AIX, z/OS, etc. Today, Operating systems is found almost in every device like
mobile phones, personal computers, mainframe computers, automobiles, TV, Toys etc.
Structure of a Computer System
A Computer System consists of:
o Users (people who are using the computer)
o Application Programs (Compilers, Databases, Games, Video player, Browsers, etc.)
o System Programs (Shells, Editors, Compilers, etc.)
o Operating System ( A special program which acts as an interface between user and
hardware)
o Hardware (CPU, Disks, Memory, etc)
Architecture
We can draw a generic architecture diagram of an Operating System which is as follows:
1. Hardware: This layer interacts with the system hardware and coordinates with all the
peripheral devices used, such as a printer, mouse, keyboard, scanner, etc. These types of
hardware devices are managed in the hardware layer.
The hardware layer is the lowest and most authoritative layer in the layered operating
system architecture. It is attached directly to the core of the system.
2. CPU Scheduling: This layer deals with scheduling the processes for the CPU. Many
scheduling queues are used to handle processes. When the processes enter the system,
they are put into the job queue. The processes that are ready to execute in the main
memory are kept in the ready queue. This layer is responsible for managing how many
processes will be allocated to the CPU and how many will stay out of the CPU.
3. Memory Management: Memory management deals with memory and moving processes
from disk to primary memory for execution and back again. This is handled by the third
layer of the operating system. All memory management is associated with this layer.
There are various types of memories in the computer like RAM, ROM.
If you consider RAM, then it is concerned with swapping in and swapping out of
memory. When our computer runs, some processes move to the main memory (RAM) for
execution, and when programs, such as calculator, exit, it is removed from the main
memory.
4. Process Management: This layer is responsible for managing the processes, i.e.,
assigning the processor to a process and deciding how many processes will stay in the
waiting schedule. The priority of the processes is also managed in this layer. The
different algorithms used for process scheduling are FCFS (first come, first served), SJF
(shortest job first), priority scheduling, round-robin scheduling, etc.
5. I/O Buffer: I/O devices are very important in computer systems. They provide users with
the means of interacting with the system. This layer handles the buffers for the I/O
devices and makes sure that they work correctly. Suppose you are typing from the
keyboard. There is a keyboard buffer attached with the keyboard, which stores data for a
temporary time. Similarly, all input/output devices have some buffer attached to them.
This is because the input/output devices have slow processing or storing speed. The
computer uses buffers to maintain the good timing speed of the processor and
input/output devices.
6. User Programs: This is the highest layer in the layered operating system. This layer
deals with the many user programs and applications that run in an operating system, such
as word processors, games, browsers, etc. You can also call this an application layer
because it is concerned with application programs.
Advantages of Layered Structure
There are several advantages of the layered structure of operating system design, such as:
1. Modularity: This design promotes modularity as each layer performs only the tasks it is
scheduled to perform.
2. Easy debugging: As the layers are discrete so it is very easy to debug. Suppose an error
occurs in the CPU scheduling layer. The developer can only search that particular layer to
debug, unlike the Monolithic system where all the services are present.
3. Easy update: A modification made in a particular layer will not affect the other layers.
4. No direct access to hardware: The hardware layer is the innermost layer present in the
design. So a user can use the services of hardware but cannot directly modify or access it,
unlike the Simple system in which the user had direct access to the hardware.
5. Abstraction: Every layer is concerned with its functions. So the functions and
implementations of the other layers are abstract to it.
Disadvantages of Layered Structure
Though this system has several advantages over the Monolithic and Simple design, there are also
some disadvantages, such as:
1. Complex and careful implementation: As a layer can access the services of the layers
below it, so the arrangement of the layers must be done carefully. For example, the
backing storage layer uses the services of the memory management layer. So it must be
kept below the memory management layer. Thus with great modularity comes complex
implementation.
2. Slower in execution: If a layer wants to interact with another layer, it requests to travel
through all the layers present between the two interacting layers. Thus it increases
response time, unlike the Monolithic system, which is faster than this. Thus an increase in
the number of layers may lead to a very inefficient design.
3. Functionality: It is not always possible to divide the functionalities. Many times, they
are interrelated and can't be separated.
4. Communication: No communication between non-adjacent layers.
OPERATING SYSTEM SERVICES
It is software that acts as an intermediary between the user and computer hardware. It is a
program with the help of which we are able to run various applications. It is the one program
that is running all the time. Every computer must have an operating system to smoothly
execute other programs. The OS coordinates the use of the hardware and application programs
for various users. It provides a platform for other application programs to work. The operating
system is a set of special programs that run on a computer system that allows it to work
properly. It controls input-output devices, execution of programs, managing files, etc.
Services of Operating System
1. Program Execution
2. Input Output Operations
3. File Management
4. Error Handling
5. Resource Management
6. Communication between Processes
Program Execution:
It is the Operating System that manages how a program is going to be executed. It loads the
program into the memory after which it is executed. The order in which they are executed
depends on the CPU Scheduling Algorithms. A few are FCFS, SJF, etc. When the program is
in execution, the Operating System also handles deadlock i.e. no two processes come for
execution at the same time. The Operating System is responsible for the smooth execution of
both user and system programs. The Operating System utilizes various resources available for
the efficient running of all types of functionalities.
Input Output Operations:
Operating System manages the input-output operations and establishes communication
between the user and device drivers. Device drivers are software that is associated with
hardware that is being managed by the OS so that the sync between the devices works
properly. It also provides access to input-output devices to a program when needed.
File Management:
The operating system helps in managing files also. If a program needs access to a file, it is the
operating system that grants access. These permissions include read-only, read-write, etc. It
also provides a platform for the user to create, and delete files. The Operating System is
responsible for making decisions regarding the storage of all types of data or files, i.e, floppy
disk/hard disk/pen drive, etc. The Operating System decides how the data should be
manipulated and stored.
Error Handling:
The Operating System also handles the error occurring in the CPU, in Input-Output devices,
etc. It also ensures that an error does not occur frequently and fixes the errors. It also prevents
the process from coming to a deadlock. It also looks for any type of error or bugs that can
occur while any task. The well-secured OS sometimes also acts as a countermeasure for
preventing any sort of breach of the Computer System from any external source and probably
handling them.
Resource Management:
System resources are shared between various processes. It is the Operating system that
manages resource sharing. It also manages the CPU time among processes using CPU
Scheduling Algorithms. It also helps in the memory management of the system. It also controls
input-output devices. The OS also ensures the proper use of all the resources available by
deciding which resource to be used by whom.
Communication between Processes:
The Operating system manages the communication between processes. Communication
between processes includes data transfer among them. If the processes are not on the same
computer but connected through a computer network, then also their communication is
managed by the Operating System itself.
Security and Protection:
In an operating system, protection is a mechanism that controls the access of the process,
programs, or users over any resources of the computer system. The operating system ensures
that all access to system resources must be monitored and controlled. It also ensures that the
external resources or peripherals must be protected from invalid access. It provides
authentication by using usernames and passwords.
These were some of the services that an operating system provides.
USER OPERATING SYSTEM INTERFACE
The user and operating system are connected with each other with the help of interface, so
interface is used to connect the user and OS.
In computers there are different types of interface that can be used for connection with
computers to users and their connection is responsible for data transfer.
Also, in computers there are different interfaces. These interfaces are not necessarily used but
can be used in computers whenever it is needed. So, different types of tasks can be performed by
the help of different interfaces.
Command line interface
The command-line interface is an interface whenever the user needs to have different commands
regarding the input and output and then a task is performed so this is called the command-line
argument and it is used to execute the output and create, delete, print, copy, paste, etc.
All these operations are performed with the help of the command-line interface.
The interface is always connected to the OS so that the command given by the user directly
works by the OS and a number of operations can be performed with the help of the command
line interface because multiple commands can be interrupted at same time and execute only one.
The command line interface is necessary because all the basic operations in the computer are
performed with the help of the OS and it is responsible for memory management. By using this
we can divide the memory and we can use the memory.
Command Line Interface advantages −
Controls OS or application
faster management
ability to store scripts which helps in automating regular tasks.
Troubleshoot network connection issues.
Command Line Interface disadvantages −
The steeper learning curve is associated with memorizing commands and a complex
syntax.
Different commands are used in different shells.
Graphical user interface
The graphical user interface is used for playing games, watching videos, etc. these are done with
the help of GUI because all these applications require graphics.
The GUI is one of the necessary interfaces because only by using the user can clearly see the
picture, play videos.
So we need GUI for computers and this can be done only with the help of an operating system.
When a task is performed in the computer then the OS checks the task and defines the interface
which is necessary for the task. So, we need GUI in the OS.
The basic components of GUIs are −
Start menu with program groups
Taskbar which showing running programs
Desktop screen
Different icons and shortcuts.
Choice of interface
The interface that is used with the help of OS for a particular task and that task can be performed
with minimum possible time and the output is shown on the screen in that case we use the
choice of interface.
The choice of interface means the OS checks the task and finds out which interface can be
suitable for a particular task. So that type of interface is called the choice of interface and this
can be done with the help of an OS.
SYSTEM CALLS
A system call is a way for a user program to interface with the operating system. The program
requests several services, and the OS responds by invoking a series of system calls to satisfy the
request. A system call can be written in assembly language or a high-level language
like C or Pascal. System calls are predefined functions that the operating system may directly
invoke if a high-level language is used.
A system call is a method for a computer program to request a service from the kernel of
the operating system on which it is running. A system call is a method of interacting with the
operating system via programs. A system call is a request from computer software to an
operating system's kernel.
The Application Program Interface (API) connects the operating system's functions to user
programs. It acts as a link between the operating system and a process, allowing user-level
programs to request operating system services. The kernel system can only be accessed using
system calls. System calls are required for any programs that use resources. Will Launch in
When a computer software needs to access the operating system's kernel, it makes a system call.
The system call uses an API to expose the operating system's services to user programs. It is the
only method to access the kernel system. All programs or processes that require resources for
execution must use system calls, as they serve as an interface between the operating system and
user programs.
Below are some examples of how a system call varies from a user function.
1. A system call function may create and use kernel processes to execute the asynchronous
processing.
2. A system call has greater authority than a standard subroutine. A system call with kernel-
mode privilege executes in the kernel protection domain.
3. System calls are not permitted to use shared libraries or any symbols that are not present
in the kernel protection domain.
4. The code and data for system calls are stored in global kernel memory.
There are various situations where you must require system calls in the operating system.
Following of the situations are as follows:
1. It is must require when a file system wants to create or delete a file.
2. Network connections require the system calls to sending and receiving data packets.
3. If you want to read or write a file, you need to system calls.
4. If you want to access hardware devices, including a printer, scanner, you need a system
call.
5. System calls are used to create and manage new processes.
The Applications run in an area of memory known as user space. A system call connects to the
operating system's kernel, which executes in kernel space. When an application creates a system
call, it must first obtain permission from the kernel. It achieves this using an interrupt request,
which pauses the current process and transfers control to the kernel.
If the request is permitted, the kernel performs the requested action, like creating or deleting a
file. As input, the application receives the kernel's output. The application resumes the procedure
after the input is received. When the operation is finished, the kernel returns the results to the
application and then moves data from kernel space to user space in memory.
A simple system call may take few nanoseconds to provide the result, like retrieving the system
date and time. A more complicated system call, such as connecting to a network device, may
take a few seconds. Most operating systems launch a distinct kernel thread for each system call
to avoid bottlenecks. Modern operating systems are multi-threaded, which means they can
handle various system calls at the same time.
Types of System Calls
There are commonly five types of system calls. These are as follows:
1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication
Now, you will learn about all the different types of system calls one-by-one.
Process Control
Process control is the system call that is used to direct the processes. Some process control
examples include creating, load, abort, end, execute, process, terminate the process, etc.
File Management
File management is a system call that is used to handle the files. Some file management
examples include creating files, delete files, open, close, read, write, etc.
Device Management
Device management is a system call that is used to deal with devices. Some examples of device
management include read, device, write, get device attributes, release device, etc.
Information Maintenance
Information maintenance is a system call that is used to maintain information. There are some
examples of information maintenance, including getting system data, set time or date, get time or
date, set system data, etc.
Communication
Communication is a system call that is used for communication. There are some examples of
communication, including create, delete communication connections, send, receive messages,
etc.
Examples of Windows and Unix system calls
There are various examples of Windows and Unix system calls. These are as listed below in the
table:
SYSTEM PROGRAMS
System programming may be defined as the act of creating System Software by using the
System Programming Languages. A system program offers an environment in which programs
may be developed and run. In simple terms, the system programs serve as a link between the user
interface (UI) and system calls. Some system programs are only user interfaces, and others are
complex. For instance, a compiler is complicated system software.
The system program is a component of the OS, and it typically lies between the user interface
(UI) and system calls. The system user view is defined by the system programs, not the system
call, because the user view interacts with system programs and is closer to the user interface.
User View It defines the interface between the It defines the user interface (UI) of the
services and the user process OS.
provided by the OS.
Action The user process requests an OS It transforms the user request into a
service using a system call. set of system calls needed to fulfil the
requirement.