OS Unit 1 Notes
OS Unit 1 Notes
OS Unit 1 Notes
The Hardware consists of memory, CPU, ALU, I/O devices, peripherals devices &
storage devices.
The application program mainly consisted of word processors, spread sheets,
compilers & web browsers defines the ways in which the resources are used to solve
the problems of the users.
The OS controls & co-ordinates the use of hardware among various application
program for various users.
Utilities: it is system software designed to help, analyze, configure, optimize or
maintain a computer. User can often install or replace additional utilities. It is used to
support computer infrastructure.
Ex: antivirus, archives, backup software, file manager, disk compression.
OS
User
program
area
Multiprogramming
o When one job needs to wait for I/O, the processor can switch to the other job
Modern OS are interrupt driven. No work -OS sit quietly. Events are signaled by the
occurrence of an interrupt/trap. A trap/exception is a software generated interrupt
caused either by an error or by a specific request from a user program that an OS
service be performed. For each type of interrupt, separate segments of code in the OS
determine what action should be taken. An ISR is responsible for dealing with the
interrupt.
User mode.
Mode bit is added to the hardware of the computer to indicate the current mode.
Kernel- 0
User -1
With mode bit we can easily distinguish the task that is executed on behalf of OS and on
behalf of the user. When user application is running- user mode. If user application
requests a service from the OS via system call, it must transition from user mode to
kernel mode.
Transition from user mode to kernel mode
Boot time, h/w starts in kernel mode. The OS is loaded and starts applications in user
mode. When interrupt occurs, h/w switches from 1 to 0. When OS gains control of the
computer, it is in 0 mode. System switches to 1 before passing control to the user
program. Dual mode of operation protects the OS from errant users. Privileged
instruction: the instruction to switch to the user mode, I/O control, timer management,
interrupts management.
Timer
OS maintains control over the cpu. To prevent a user program getting stuck in an infinite
loop or calling system services and never returning control to the OS, we use timer. A
timer can be set to interrupt the computer after a specified period. The period may be
fixed (1/60 second) or variable( from 1millisec to 1 second).
A program does nothing unless its instructions are executed by a CPU. Process –
complier, word processing program, system task( sending output to a printer). 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. Program is a passive entity such as the contents of a
file stored on disk. Process is an active entity.
Memory management
The main memory is central to the operation of a modern computer system. It contains
large array of words/bytes. Each word has its own address. Main memory is repository
of quickly accessible data shared by the CPU and I/O devices. The central processor
reads instructions from main memory during the instruction fetch cycle and both reads
and writes data from main memory during the data fetch cycle. The main memory is the
storage device that the CPU is able to address and access directly.
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 OS is responsible for the following activities in
connection with memory management.
Storage Management
File: collection of related information defined by its creator. File represents programs
and data. Data files may be numeric, alphabetic, alphanumeric or binary. Files are
normally organized in to directories to make them easier to use. When multiple users
have access to files, it may be desirable to control by whom and in what ways files may
be accessed.
The OS is responsible for the following activities in connection with the disk
management.
Free space management
Storage allocation
Disk scheduling
3. I/O systems
Command-Interpreter System
o One of the most important systems programs for an operating system is the
command interpreter, which is the interface between the user and the OS.
o Some operating systems include the command interpreter in the kernel.
o Other operating systems, such as MS-DOS and UNIX, treat the command
interpreter as a special program that is running when a job is initiated, or when a
user first logs on.
o The program that reads and interprets control statements is called variously:
o command-line interpreter
o shell (in UNIX)
o Its function is to get and execute the next command statement.
o Many commands are given to the operating system by control statements which
deal with:
o process creation and management
o I/O handling
o secondary-storage management
o main-memory management
o file-system access
o Protection and networking
SYSTEM CALLS
• System provides interface between the process & the OS.
• The calls are generally available as assembly language instruction & certain system
allow system calls to be made directly from a high level language program.
• Several language have been defined to replace assembly language program.
• A system call instruction generates an interrupt and allows OS to gain control of the
processors.
• System calls occur in different ways depending on the computer. Some time more
information is needed to identify the desired system call. The exact type & amount of
information needed may vary according to the particular OS & call.
• Mostly accessed by programs via API rather than direct system calls.
• Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based
systems and Java API for JVM
System Call Implementation
• Typically, a number associated with each system call
o System-call interface maintains a table indexed according to these numbers
• The system call interface invokes intended system call in OS kernel and returns
status of the system call and any return values
• The caller need know nothing about how the system call is implemented
o Just needs to obey API and understand what OS will do as a result call
o Most details of OS interface hidden from programmer by API
Managed by run-time support library (set of functions built into
libraries included with compiler)
C program invoking printf() library call, which calls write() system call
System Call Parameter Passing
Often, more information is required than simply identity of desired system call
o Exact type and amount of information vary according to OS and call
Three general methods used to pass parameters to the OS
o Simplest: pass the parameters in registers
In some cases, may be more parameters than registers
o Parameters stored in a block, or table, in memory, and address of block
passed as a parameter in a register
This approach taken by Linux and Solaris
o Parameters placed, or pushed, onto the stack by the program and popped off
the stack by the operating system
o Block and stack methods do not limit the number or length of parameters
being passed
Parameter Passing via Table
TYPES OF SYSTEM CALLS
System calls may be grouped roughly into 5 categories
Process control
File management
Device management
Information maintenance
Communications
Process Management:- A system call can be used to terminate the program either
normally or abnormally. Reasons for abnormal termination are dump of memory,
error message generated etc.
Debugger is mainly used to determine problem of the dump & returns back the dump
to the OS.
In normal or abnormal situations the OS must transfer the control to the command
interpreter system.
In batch system the command interpreter terminates the execution of job &
continues with the next job.
Some systems use control cards to indicate the special recovery action to be taken in
case of errors.
Normal & abnormal termination can be combined at some errors level. Error level is
defined before & the command interpreter uses this error level to determine next
action automatically.
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
MS-DOS:-
MS-DOS is an example of single tasking system, which has command interpreter system i.e.
invoked when the computer is started. To run a program MS-DOS uses simple method. It
does not create a process when one process is running MS-DOS the program into memory &
gives the program as much as possible. It lacks the general multitasking capabilities.
BSD:-
Free BSD is an example of multitasking system. In free BSD the command interpreter may
continue running while other program is executing. FORK is used to create new process.
FILE MANAGEMENT
System calls can be used to create & deleting of files. System calls may require the
name of the files with attributes for creating & deleting of files.
Other operation may involve the reading of the file, write & reposition the file after it
is opened.
Finally we need to close the file.
For directories some set of operation are to be performed. Sometimes we require to
reset some of the attributes on files & directories. The system call get file attribute &
set file attribute are used for this type of operation.
create file, delete file
open, close
read, write, reposition
get file attributes, set file attributes
DEVICE MANAGEMENT:-
The system calls are also used for accessing devices.
Many of the system calls used for files are also used for devices.
In multi user environment the requirement are made to use the device. After using
the device must be released using release system call the device is free to be used
by another user. These function are similar to open & close system calls of files.
Read, write & reposition system calls may be used with devices.
MS-DOS & UNIX merge the I/O devices & the files to form file services structure. In
file device structure I/O devices are identified by file names.
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
INFORMATION MAINTAINANCE:-
Many system calls are used to transfer information between user program & OS.
Example:- Most systems have the system calls to return the current time & date,
number of current users, version number of OS, amount of free memory or disk
space & so on.
In addition the OS keeps information about all its processes & there are system calls
to access this information.
get time or date, set time or date
get system data, set system data
get process, file, or device attributes
set process, file, or device attributes
COMMUNICATION:-
create, delete communication connection
send, receive messages
transfer status information
attach or detach remote devices
There are two modes of communication,
1. Message Passing Models:-
In this information is exchanged using inter-process communication facility provided
by OS.
Before communication the connection should be opened.
The name of the other communicating party should be known, it can be on the same
computer or it can be on another computer connected by a computer network.
Each computer in a network may have a host name like IP name similarly each
process can have a process name which can be translated into equivalent identifier
by OS.
The get host id & process id system call do this translation. These identifiers are then
passed to the open & close connection system calls.
The recipient process must give its permission for communication to take place with
an accept connection call.
Most processes receive the connection through special purpose system program
dedicated for that purpose called daemons. The daemon on the server side is called
server daemon & the daemon on the client side is called client daemon.
2. Shared Memory:-
In this the processes uses the map memory system calls to gain access to memory
owned by another process.
The OS tries to prevent one process from accessing another process memory.
In shared memory this restriction is eliminated and they exchange information by
reading and writing data in shared areas. These areas are located by these processes
and not under OS control.
They should ensure that they are not writing to same memory area.
Both these types are commonly used in OS and some even implement both.
Message passing is useful when small number of data need to be exchanged since
no conflicts are to be avoided and it is easier to implement than in shared memory.
Shared memory allows maximum speed and convenience of communication as it is
done at memory speed when within a computer.
System Programs
System programs provide a convenient environment for program development and
execution.
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.
That information is then formatted, and is printed to the terminal or other output device
or file.
File modification: Several text editors may be available to create and modify the
content of files stored on disk or tape.
Programming-language support: Compilers, assemblers, and interpreters for
common programming languages (such as C, C++, Java, Visual Basic, and PERL) are
often provided to the user with the operating system.
Some of these programs are now priced and provided separately.
Program loading and execution: Once a program is assembled or compiled, it must
be loaded into memory to be executed.
The system may provide absolute loaders, relocatable loaders, linkage editors, and
overlay loaders.
Debugging systems for either higher-level languages or machine language are needed
also.
Communications: These programs provide the mechanism for creating virtual
connections among processes, users, and different computer systems.
They allow users to send messages to one another's screens, to browse web pages, to
send electronic-mail messages, to log in remotely, or to transfer files from one machine
to another.
Most users’ view of the operation system is defined by system programs, not the actual
system calls.
Most operating systems are supplied with programs that solve common problems, or
perform common operations.
Such programs include web browsers, word processors and text formatters,
spreadsheets, database systems, compiler compilers, plotting and statistical-analysis
packages, and games.
These programs are known as system utilities or application programs.
UNIX Structure
2. Layered Approach:
The operating system is divided into a number of layers (levels), each built on top of
lower layers.
The bottom layer (layer 0), is the hardware; the highest (layer N) is the user
interface.
The main advantage of the layered approach is modularity.
With modularity, layers are selected such that each uses functions (operations) and
services of only lower-level layers.
This approach simplifies debugging and system verification.
The first layer can be debugged without any concern for the rest of the system,
because, by definition, it uses only the basic hardware (which is assumed correct) to
implement its functions.
Thus, the design and implementation of the system are simplified when the system
is broken down into layers.
The major difficulty with the layered approach involves the careful definition of the
layers, because a layer can use only those layers below it.
A final problem with layered implementations is that they tend to be less efficient
than other types.
Each layer adds overhead to the system call; the net result is a system call that
takes longer than does one on a non layered system.
Slower
Advantages
The main advantage is simplicity of construction and debugging.
Modularity
Disadvantages
The main difficulty is defining the various layers.
The main disadvantage is that the OS tends to be less efficient than other
implementations.
Slower
Less efficient
Virtual Machines
A virtual machine takes the layered approach to its logical conclusion. It treats hardware
and the operating system kernel as though they were all hardware. A virtual machine
provides an interface identical to the underlying bare hardware. The operating system
creates the illusion of multiple processes, each executing on its own processor with its own
(virtual) memory. The resources of the physical computer are shared to create the virtual
machines. CPU scheduling can create the appearance that users have their own processor.
Disadvantages:
The virtual machine concept is difficult to implement.
Due to isolation, no direct sharing of resources is permitted.
JVM consists of
o class loader
o class verifier
o Runtime interpreter to execute platform-neutral bytecodes.
Each programming language has their own compiler and execution engine. Execution engine
for java is JVM. It is compatible with almost all OS and can be implemented independently
on any hardware. Whenever you type java command in the command prompt to run java
class, an instance of JVM is created.
JIT compiler that turns the platform-neutral byte codes into native machine language for
the host computer. The JVM makes it possible to develop programs that are architecture
neutral and portable. Java takes advantage of the complete environment that a virtual
machine implements. Its virtual-machine design provides a secure, efficient, object
oriented, portable, and architecture-neutral platform on which to run Java programs.
Advantages:
Platform independence: Written once and executed on multiple platforms
Security: JVM has built-in security features.
Disadvantage:
Programs run on JVM takes longer time to execute.