FOS Module1
FOS Module1
• An Operating System is a program that manages the computer hardware. It also provides a
basis for application programs and acts as an intermediary between the computer user and
the computer hardware.
• Operating systems are designed to be convenient, others to be efficient, and others some
combination of the two.
• User View:
➢ The user view of the computer depends on the interface used.
➢ Some users may use PC’s. In this the system is designed so that only one user can utilize
the resources and mostly for ease of use where the attention is mainly on performances
and not on the resource utilization.
➢ Some users may use a terminal connected to a mainframe or minicomputers.
➢ Other users may access the same computer through other terminals. These users may
share resources and exchange information. In this case the OS is designed to maximize
resource utilization- so that all available CPU time, memory & I/O are used efficiently.
➢ Other users may sit at workstations, connected to the networks of other workstation and
servers. In this case OS is designed to compromise between individual visibility & resource
utilization.
• System View
➢ We can view system as resource allocator i.e. a computer system has many resources
that may be used to solve a problem. The OS acts as a manager of these resources. The OS
must decide how to allocate these resources to programs and the users so that it can
operate the computer system efficiently and fairly.
➢ A different view of an OS is that it need to control various I/O devices & user programs
i.e. an OS is a control program used to manage the execution of user program to prevent
errors and improper use of the computer.
➢ Resources can be either CPU Time, memory space, file storage space, I/O devices and so
on.
➢ Each device controller is in charge of a specific type of device (for example, disk drives,
audio devices, and video displays). The CPU and the device controllers can execute
concurrently, competing for memory cycles.
➢ To ensure orderly access to the shared memory, a memory controller is provided whose
function is to synchronize access to the memory.
➢ Bootstrap program - For a computer to start running, when it is powered up or rebooted-
it needs to have an initial program to run.
➢ Bootstrap program is stored in ROM or electrically erasable programmable read-only
memory (EPROM) known by the general term firmware within the computer hardware.
➢ The occurrence of an event is usually signaled by an Interrupt from either the hardware or
the software. Hardware may trigger an interrupt at any time by sending a signal to the CPU,
usually by way of the system bus. Software may trigger an interrupt by executing a special
operation called system call (Monitor call).
➢ When the CPU is interrupted, it stops what it is doing and immediately transfers execution
to a fixed location. The fixed location usually contains the starting address where the
service routine for the interrupt is located.
➢ The interrupt service routine executes; on completion, the CPU resumes the interrupted
computation. A time line of this operation is shown in Figure 1.3.
Figure 1.3. Interrupt time line for a single process doing output.
➢ Interrupt transfers control to the interrupt service routine generally, through the
interrupt vector, which contains the addresses of all the service routines.
➢ Interrupt architecture must save the address of the interrupted instruction.
➢ Incoming interrupts are disabled while another interrupt is being processed to prevent a
lost interrupt.
➢ A trap is a software-generated interrupt caused either by an error or a user request.
➢ An operating system is interrupt driven. The operating system preserves the state of the
CPU by storing registers and the program counter
➢ To Determine which type of interrupt has occurred:
▪ Polling
▪ vectored interrupt system
➢ Separate segments of code determine what action should be taken for each type of
interrupt
• I/O Structure
➢ After I/O starts, control returns to user program only upon I/O completion
▪ Wait instruction idles the CPU until the next interrupt
▪ Wait loop (contention for memory access)
▪ At most one I/O request is outstanding at a time, no simultaneous I/O processing.
➢ After I/O starts, control returns to user program without waiting for I/O completion
▪ System call – request to the operating system to allow user to wait for I/O
completion
▪ Device-status table contains entry for each I/O device indicating its type, address,
and state
▪ Operating system indexes into I/O device table to determine device status and to
modify table entry to include interrupt.
▪ Device controller transfers blocks of data from buffer storage directly to main
memory without CPU intervention.
▪ Only one interrupt is generated per block, rather than the one interrupt per byte.
▪ Figure 1.5 shows all components of computer system.
• Storage Structure
➢ The CPU can load instructions only from memory, so any programs to run must be stored
there.
➢ General-purpose computers run most of their programs from rewriteable memory, called
main memory (also called Random Access Memory or RAM).
➢ Main memory commonly is implemented in a semiconductor technology called Dynamic
Random Access Memory or DRAM.
➢ The read-only memory (ROM) cannot be changed, only static programs are stored there.
➢ EEPROM cannot be changed frequently and so contains mostly static programs. For
example, smart phones have EEPROM to store their factory-installed programs.
➢ All forms of memory provide an array of words. Each word has its own address. Interaction
is achieved through a sequence of load or store instructions to specific memory addresses.
➢ The load instruction moves a word from main memory to an internal register within the
CPU, whereas the store instruction moves the content of a register to main memory. The
CPU automatically loads instructions from main memory for execution.
➢ A typical instruction-execution cycle, as executed on a system with Von Neumann
architecture, first fetches an instruction from memory and stores that instruction in the
Instruction Register (IR).
➢ The instruction is then decoded and may cause operands to be fetched from memory and
stored in some internal register. After the instruction on the operands has been executed,
the result may be stored back in memory.
➢ The programs and data to reside in main memory permanently. This arrangement usually
is not possible for the following two reasons:
▪ Main memory is usually too small to store all needed programs and data permanently.
▪ Main memory is a volatile storage device that loses its contents when power is turned
off or otherwise lost.
➢ Computer systems provide secondary storage as an extension of main memory which can
hold large quantities of data permanently.
➢ The most commonly used secondary storage device is magnetic disk, which provides
storage for both programs and data.
➢ The wide variety of storage systems in a computer system can be organized in a hierarchy
(Figure 1.4) according to speed and cost.
➢ Example: Disk controller microprocessor receives a sequence of requests from the main
CPU and implements its own queue and scheduling algorithm.
➢ PCs contain a microprocessor in the keyboard to convert the key strokes into codes to be
sent to the CPU.
➢ The use of special purpose microprocessors does not turn a single processor system into
a multiprocessor.
➢ The ability to continue providing the service proportional to the level of surviving
hardware is called Graceful Degradation.
➢ A system goes beyond the graceful degradation are called fault tolerant, because they
suffer a failure of any single component and still continue operation.
➢ The benefit here is that many processes can run simultaneously – N processes can run if
N CPUs without causing a detoriation of performance.
➢ Care must be taken for Controlling I/O to ensure that the data reach to appropriate
processor otherwise one processor is sitting idle while another is overhead.
➢ Multiprocessing can cause a system to change its memory access model from uniform
memory access (UMA) to non-uniform memory access (NUMA).
➢ UMA is defined as the situation in which access to any RAM from any CPU takes the same
amount of time.
➢ Blade Servers are a recent development in which multiple processor boards, I/0 boards,
and networking boards are placed in the same chassis.
➢ The difference between these and traditional multiprocessor systems is that each blade-
processor board boots independently and runs its own operating system.
➢ Some blade-server boards are multiprocessor as well, which blurs the lines between types
of computers.
➢ A layer of cluster software runs on the cluster nodes. Each node can monitor one or more
of the others (over the LAN). If the monitored machine fails, the monitoring machine can
take ownership of its storage and restart the applications that were running on the failed
machine.
➢ In Asymmetric clustering, one machine is in hot standby mode, while the other is running
the applications.
➢ The hot-standby host machine does nothing but monitor the active server. If that server
fails, the hot-standby host becomes the active server.
➢ In Symmetric mode, two or more hosts are running applications and are monitoring each
other. This mode is obviously more efficient, as it uses all of the available hardware. It does
require that more than one application be available to run.
backing store for main memory. This can be achieved by using a technique called virtual
memory that allows for the execution of job i.e. not complete in memory.
➢ Time sharing system should also provide a file system & file system resides on collection of
disks so this need disk management. It supports concurrent execution, job synchronization
& communication.
➢ The operating system and the users share the hardware and software resources of the
computer system.
➢ When sharing, if error in a program, might affect the execution of the program.
➢ Without protection against these sorts of errors, either the computer must execute only
one process at a time or all output must be suspect.
➢ A bit, called the mode bit, is added to the hardware of the computer to indicate the current
mode: kernel (0) or user (1).
➢ User mode when executing harmless code in user applications
➢ Kernel mode when executing potentially dangerous code in the system kernel.
➢ When a user application requests a service from the operating system (via a system call), it
must transition from user to kernel mode to fulfill the request shown in figure 1.9.
➢ At system boot time, the hardware starts in kernel mode. The operating system is then
loaded and starts user applications in user mode.
➢ Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel mode
(that is, changes the state of the mode bit to 0).
➢ Whenever the operating system gains control of the computer, it is in kernel mode. The
system always switches to user mode (by setting the mode bit to 1) before passing control
to a user program.
➢ The dual mode of operation provides us with the means for protecting the operating system
from errant users-and errant users from one another.
1.5.2 Timer
➢ To prevent user program getting stuck in an infinite loop or not 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 (EX: 1/60 second) or variable (EX: from 1ms to 1second).
➢ Before turning over the control to the user, the OS ensures that the timer is set to interrupt.
If timer interrupts, control transfers automatically to OS.
➢ Timer is used to prevent a user program running long.
➢ Timer control is a privileged instruction, (requiring kernel mode. )
➢ Process needs resources such as CPU, memory, I/O, files, Initialization data to accomplish its
task.
➢ Process termination requires reclaim of any reusable resources.
➢ Single-threaded process has one program counter specifying location of next instruction to
execute. Process executes instructions sequentially, one at a time, until completion.
➢ Multi-threaded process has one program counter per thread.
➢ Typically system has many processes, some user, and some operating system running
concurrently on one or more CPUs. Concurrency by multiplexing the CPUs among the
processes / threads.
➢ A process is the unit of work in a system. Such a system consists of a collection of processes,
some of which are operating-system processes (those that execute system code) and the rest
of which are user processes (those that execute user code). All these processes can
potentially execute concurrently – by multiplexing the CPU among them on a single CPU.
➢ The operating system is responsible for the following activities in connection with process
management:
▪ Creating and deleting both user and system processes
▪ Suspending and resuming processes
▪ Providing mechanisms for process synchronization
▪ Providing mechanisms for process communication
▪ Providing mechanisms for deadlock handling
➢ The entire speed of computer system depends on the speed of the disk sub system.
➢ Magnetic tape drives and CD and DVD drives and Platters typical tertiary storage devices.
➢ The media (tapes and optical platters) vary between WORM (write once, read many times)
and RW (read-write) formats.
1.6.3. Caching:
➢ There are many cases in which a smaller higher-speed storage space serves as a cache, or
temporary storage, for some of the most frequently needed portions of larger slower storage
areas.
➢ The hierarchy of memory storage ranges from CPU registers to hard drives and external
storage. (See table below.)
➢ The OS is responsible for determining what information to store in what level of cache, and
when to transfer data from one level to another.
➢ The proper choice of cache management can have a profound impact on system performance.
➢ Data read in from disk follows a migration path from the hard drive to main memory, then
to the CPU cache, and finally to the registers before it can be used, while data being written
follows the reverse path. Each step (other than the registers) will typically fetch more data
than is immediately needed, and cache the excess in order to satisfy future requests faster.
For writing, small amounts of data are frequently buffered until there is enough to fill an
entire "block" on the next output device in the chain.
➢ The issues get more complicated when multiple processes (or worse multiple computers)
access common data, as it is important to ensure that every access reaches the most up-to-
date copy of the cached data (amongst several copies in different cache levels. )
➢ Important principle, performed at many levels in a computer (in hardware, operating
system, software).
➢ Information in use copied from slower to faster storage temporarily.
➢ In multitasking environment, where CPU is switched back and forth among various
processes, care must be taken that, if several processes wish to access same file, then each of
these processes obtains recently updated value.
➢ When only one process executes at time, no such difficulties arises.
➢ Multitasking environments must be careful to use most recent value, no matter where it is
stored in the storage hierarchy.
➢ Multiprocessor environment must provide cache coherency in hardware such that all CPUs
have the most recent value in their cache.
➢ Many commands are given to the OS through control statements when the user logs on, a
program that reads & interprets control statements is executed automatically. This program
is sometimes called the control card interpreter or command line interpreter and is also
called as shell.
➢ The command statements themselves deal with process creation & management, I/O
handling, secondary storage management, main memory management, file system access,
protection & Network.
➢ The CI itself contains the code to execute the command. For example, to delete a file may
cause the CI to jump to a section of its code that sets up the parameters and makes
appropriate system call.
➢ An alternative approach used in UNIX implements commands through system programs. The
UNIX command to delete a file: rm file.txt.
➢ Figure 1.14 shows the Bourne shell command interpreter being used on Solaris 10.
➢ 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 a high-level Application Program Interface (API) rather
than direct system call use
➢ The API specifies a set of functions that are available to an application programmer,
including the parameters that are passed to each function and the return values the
programmer can expect.
➢ Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems
(including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java
virtual machine (JVM).
➢ System call sequence to copy the contents of one file to another file shown in figure 1.15
❖ The use of APIs instead of direct system calls provides for greater program portability
between different systems. The API then makes the appropriate system calls through
the system call interface, using a table lookup to access specific numbered system calls,
as shown in Figure 1.16.
Figure 1.16. The handling of a user application invoking the open() system call.
❖ Parameters are generally passed to system calls via registers, or less commonly, by
values pushed onto the stack. Large blocks of data are generally accessed indirectly,
through a memory addressed passed in register or on stack, as shown in Figure 1.17.
❖ Process control
▪ 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
❖ File management
▪ create file, delete file
▪ open, close
▪ read, write, reposition
▪ get file attributes, set file attributes
❖ Device management
▪ request device, release device
▪ read, write, reposition
▪ get device attributes, set device attributes
▪ logically attach or detach devices
❖ Information maintenance
▪ 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
❖ Communications
▪ create, delete communication connection
▪ send, receive messages
▪ transfer status information
▪ attach or detach remote devices
❖ Protection
▪ Set permission, get permission
▪ Allow user, deny user
1. PROCESS CONTROL:
➢ A running program needs to be able to halt its execution either normally (end) or
abnormally (abort).
➢ If a system call is made to terminate the currently running program abnormally, or if the
program runs into a problem and causes an error trap, a dump of memory is sometimes
taken and an error message generated.
➢ The dump is written to disk and may be examined by debugger - a system program
designed to aid the programmer in finding and correcting bugs-to determine the cause of
the problem.
➢ The operating system must transfer control to the command interpreter to read the next
command.
➢ In an interactive system, the command interpreter simply continues with the next
command; it is assumed that the user will issue an appropriate command to respond to any
error.
➢ In a GUI system, a pop-up window might alert the user to the error and ask for guidance.
➢ In a batch system, the command interpreter usually terminates the entire job and continues
with the next job.
2. 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.
3. 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 functions 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.
4. 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.
5. COMMUNICATION:-
There are two modes of communication,
❖ 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.
❖ 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.
6. PROTECTION:
➢ Provides a mechanism for controlling access to the resources provided by a computer
system.
➢ Protection was a concern only on multiprogrammed computer systems with several
users.
➢ System calls providing protection include set permission and get permission, which
manipulate the permission settings of resources such as files and disks.
➢ The allow user and deny user system calls specify whether particular users can-or
cannot-be allowed access to certain resources.