0% found this document useful (0 votes)
6 views35 pages

Lecture notes

Uploaded by

kmitdata
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
6 views35 pages

Lecture notes

Uploaded by

kmitdata
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 35

OPERATING SYSTEMS

UNIT – 1

Introduction to Operating Systems, System structures: What operating systems do;


Computer System organization; Computer System architecture; Operating System structure;
Operating System operations; Process management; Memory management; Storage
management; Protection and security; Distributed system; Special-purpose systems; Computing
environments.Operating System Services; User - Operating System interface; System calls;
Types of system calls; System programs; Operating System design and implementation;
Operating System structure; Virtual machines; Operating System generation; System boot.
UNIT 1: INTRODUCTION

Operating System
 An OS is a program that acts as an intermediary between
o computer-user and
o computer-hardware.
 It also provides a basis for application-programs
 Goals of OS:
o To execute programs.
o To make solving user-problems easier.
o To make the computer convenient to use.
 The OS (also called kernel) is the one program running at all times on the computer.
 Different types of OS:
o Mainframe OS is designed to optimize utilization of hardware.
o Personal computer (PC) OS supports complex game, business application.
o Handheld computer OS is designed to provide an environment in which a user can easily
o interface with the computer to execute programs.

 What Operating Systems do?


 Four components of a computer (Figure 1.1):
o Hardware
o OS
o Application programs and
o Users

Figure 1.1 Abstract view of the components of a computer system

• Hardware provides basic computing-resources:


o CPU
o memory and
o I/O devices.
• Application-program defines how the resources are used to solve computing-problems of the users.
Ex: word processors, spread sheets, compilers.
• The OS controls & co-ordinates the use of hardware among various application-program for various
users.
• Two views of OS:
o 1) User and 2) System.
User View
• The user's view of the computer depends on the interface being used:
o 1 Most users use a PC consisting of a monitor, keyboard and system-unit.
• The OS is designed mostly for ease of use.
• Some attention is paid to performance.
 No attention is paid to resource utilization.
 The OS is optimized for the single-user experience.
o Some users use a terminal connected to a mainframe or (a minicomputer). The OS
is designed
o to maximize resource utilization.
o to assure that no individual user takes more than her fair share.
• Some users use a workstation connected to network.
• The users have dedicated resources such as networking and servers.
• The OS is designed to compromise between
o individual usability and
o resource utilization.
o 4. Some users use a handheld computer.
• The OS is designed mostly for individual usability.
• Performance per unit of battery life is a very important factor.

System View
• An OS as a resource allocator
o Resources used to solve a computing-problem:
 CPU time
 memory-space
 file-storage space and
 I/0 devices.
o The OS manages and allocates the above resources to programs and the users.
• An OS is a control program
o The OS is needed to control:
 operations of I/0 devices and
 execution of user-programs to prevent errors.
Computer System Organization
• A computer consists of
o one or more CPUs and
o no. of device-controllers (Figure 1.2).
• Controller is in charge of a specific type of device (for ex: audio devices).
• CPU and controllers can execute concurrently.
• A memory-controller is used to synchronize access to the shared-memory.
• Following events occur for a computer to start running:
o Bootstrap program is an initial program that runs when computer is powered-up.
o Bootstrap program
 initializes all the system from registers to memory-contents and
 loads OS into memory.
o Then, OS
 starts executing the first process (such as "init") and
 waits for some event to occur.
o The occurrence of an event is signaled by an interrupt from either the hardware or the
software (Figure 1.3).
o Hardware may trigger an interrupt by sending a signal to the CPU. ii)
Software may trigger an interrupt by executing a system-call.
o When CPU is interrupted, the CPU
 stops current computation and
 transfers control to ISR (interrupt service routine).
o Finally, the ISR executes; on completion, the CPU resumes the interrupted computation.
Common Functions of Interrupts
• Interrupt transfers control to the ISR 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.
• A modern OS is interrupt-driven.

Figure 1.2 A modern computer system

Figure 1.3 Interrupt time line for a single process doing output
Storage Structure
• Programs must be in main-memory (also called RAM) to be executed.
• Interaction with memory is done through a series of load or store instructions.
o Load Instruction
o Moves a word from main-memory to an internal register within the CPU.
o 2. Store Instruction
o Moves the content of a register to main-memory.
• Also, the CPU automatically loads instructions from main-memory for execution.
• Ideally, we want the programs & data to reside in main-memory permanently. This is not possible for
2 reasons:
 Main-memory is small.
 Main-memory is volatile i.e. it loses its contents when powered-off.
• Most computers provide secondary-storage as an extension of main-memory.
o For ex: magnetic disk.
• Main requirement:
o The secondary-storage must hold large amount of data permanently.
• The wide range of storage-systems can be organized in a hierarchy (Figure 1.4).
• The higher levels are expensive, but they are fast.
o The lower levels are inexpensive, but they are slow.

Figure 1.4 Storage-device hierarchy


I/O Structure
• A computer consists of CPUs and multiple device controllers (Figure 1.5).
• A controller is in charge of a specific type of device.
• The controller maintains
o some local buffer and
o set of special-purpose registers.
• Typically, OS has a device-driver for each controller.
• Interrupt-driven I/O:
o Driver loads the appropriate registers within the controller.
o Controller examines the contents of registers to determine what action to take.
o Controller transfers data from the device to its local buffer.
o Controller informs the driver via an interrupt that it has finished its operation.
o Driver then returns control to the OS.
• Problem: Interrupt-driven I/O produces high overhead when used for bulk data-transfer.
Solution: Use DMA (direct memory access).
• In DMA, the controller transfers blocks of data from buffer-storage directly to main memory without
CPU intervention.

Figure 1.5 How a modern computer system works


Computer System Architecture
• Single-Processor Systems
• Multiprocessor Systems
• Clustered Systems

Single Processor Systems


• The system has only one general-purpose CPU.
• The CPU is capable of executing a general-purpose instruction-set.
• These systems range from PDAs through mainframes.
• Almost all systems have following processors:
o Special Purpose Processors
o Include disk, keyboard, and graphics controllers.
 General Purpose Processors
o Include I/O processors.
• Special-purpose processors run a limited instruction set and do not run user-processes.

Multiprocessor Systems
• These systems have two or more processors which can share:
o → bus → clock → memory/peripheral devices
• Advantages:
• Increased Throughput
• By increasing no. of processors, we expect to get more work done in less time.
• Economy of Scale
• These systems are cheaper because they can share
 → peripherals → mass-storage → power-supply.
o If many programs operate on same data, they will be stored on one disk & all processors can
share them.
• Increased Reliability
o The failure of one processor will not halt the system.
• Two types of multiple-processor systems:
o Asymmetric multiprocessing(AMP) and 2) Symmetric multiprocessing(SMP)
• Asymmetric Multiprocessing
• This uses master-slave relationship (Figure 1.6).
• Each processor is assigned a specific task.
• A master-processor controls the system.
o The other processors look to the master for instruction.
• The master-processor schedules and allocates work to the slave-processors.
• Symmetric Multiprocessing
• Each processor runs an identical copy of OS.
• All processors are peers; no master-slave relationship exists between processors.
• Advantages:
o Many processes can run simultaneously.
o Processes and resources are shared dynamically among the various processors.
• Disadvantage:
o Since CPUs are separate, one CPU may be sitting idle while another CPU is overloaded. This
results in inefficiencies.

Figure 1.6 Symmetric multiprocessing architecture


Clustered Systems
• These systems consist of two or more systems coupled together (Figure 1.7).
• These systems share storage & closely linked via LAN.
• Advantage:
o Used to provide high-availability service.
• High-availability is obtained by adding a level of redundancy in the system.
• Working procedure:
o A cluster-software runs on the cluster-nodes.
o Each node can monitor one or more other nodes (over the LAN).
o If the monitored-node fails, the monitoring-node can
 take ownership of failed-node’s storage and
 restart the applications running on the failed-node.
o The users and clients of the applications see only a brief interruption of service.
• Two types are:
• Asymmetric and 2) Symmetric
Asymmetric Clustering
• One node is in hot-standby mode while the other nodes are running the applications.
• The hot-standby node does nothing but monitor the active-server.
• If the server fails, the hot-standby node becomes the active server.
Symmetric Clustering
• Two or more nodes are running applications, and are monitoring each other.
• Advantage:
o This mode is more efficient, as it uses all of the available hardware.
• It does require that more than one application be available to run.

Figure 1.7 General structure of a clustered system

Operating System Structure


• Batch systems
• Multiprogrammed systems
• Time-Sharing systems

Batch Systems
• Early computers were physically enormous machines run from a console.
• The common input devices were card readers and tape drives.
• The common output devices were line printers, tape drives, and card punches.
• The user
o prepared a job which consisted of the program, the data, and control information
o submitted the job to the computer-operator.
• The job was usually in the form of punch cards.
• At some later time (after minutes, hours, or days), the output appeared.
• To speed up processing, operators batched together jobs with similar needs and ran them through the
computer as a group.
• Disadvantage:
o The CPU is often idle, because the speeds of the mechanical I/O devices.

Multiprogrammed Systems
• Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has one to
execute.
• The idea is as follows:
o OS keeps several jobs in memory simultaneously (Figure 1.8).
o OS picks and begins to execute one of the jobs in the memory. Eventually, the job may have
to wait for some task, such as an I/O operation, to complete.
o OS simply switches to, and executes, another job.
o When that job needs to wait, the CPU is switched to another job, and so on.
o As long as at least one job needs to execute, the CPU is never idle.
• 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. Making this decision is job scheduling.
• If several jobs are ready to run at the same time, the system must choose among them. Making this
decision is CPU scheduling.

Figure 1.8 Memory layout for a multiprogramming system

Time Sharing Systems


• Time sharing (or multitasking) is a logical extension of multiprogramming.
• The CPU executes multiple jobs by switching between them.
• Switching between jobs occur so frequently that the users can interact with each program while it is
running.
• Many users are allowed to share the computer simultaneously.
• CPU scheduling and multiprogramming are used to provide each user with a small portion of a time-
shared computer.
• To obtain a good response time, jobs may have to be swapped in and out of main memory to the disk
(called as backing store).
• Virtual memory is a technique that allows the execution of a job that may not be completely in
memory.
• Advantage of virtual-memory:
o Programs can be larger than physical memory.
• Main requirements:
• The system must provide a file-system.
• The system must provide disk-management.
• The system must provide CPU-scheduling to support concurrent execution.
• The system must provide job-synchronization to ensure orderly execution.

Operating System Operations


• Modern OS is interrupt driven.
• Events are always signaled by the occurrence of an interrupt or a trap.
• A trap is a software generated interrupt caused either by
o error (for example division by zero) or
o 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.
• ISR (interrupt service routine) is provided that is responsible for dealing with the interrupt.

Dual Mode Operation


• Problem: We must be able to differentiate between the execution of
o OS code and
o user-defined code.
• Solution: Most computers provide hardware-support.
• We have two modes of operation (Figure 1.9):
o User mode and
o Kernel mode
• A mode bit is a bit added to the hardware of the computer to indicate the current mode:
i.e. kernel (0) or user (1)

Figure 1.9 Transition from user to kernel mode

• Working principle:
o At system boot time, the hardware starts in kernel-mode.
o The OS is then loaded and starts user applications in user-mode.
o 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).
o The system always switches to user-mode (by setting the mode bit to 1) before passing control
to a user-program.
• Dual mode protects
o OS from errant users and
o errant users from one another.
• Privileged instruction is executed only in kernel-mode.
• If an attempt is made to execute a privileged instruction in user-mode, the hardware treats it as illegal
and traps it to the OS.
• A system calls are called by user-program to ask the OS to perform the tasks on behalf of the user
program.
• Timer
• Problem: We cannot allow a user-program to get stuck in an infinite loop and never return control to
the OS.
• Solution: We can use a timer.
• A timer can be set to interrupt the computer after a specific period.
• The period may be
o fixed (for ex: 1/60 second) or
o variable (for ex: from 1ns to 1ms).
• A variable timer is implemented by
o a fixed-rate clock and
o a counter.
• Working procedure:
o The OS sets the counter.
o Every time the clock ticks, the counter is decremented.
o When the counter reaches 0, an interrupt occurs.
• The instructions that modify the content of the timer are privileged instructions.

Process Management
• The OS is responsible for the following activities:
o Creating and deleting both user and system processes
o Suspending and resuming processes
o Providing mechanisms for process synchronization
o Providing mechanisms for process communication
o Providing mechanisms for deadlock handling
• A process needs following resources to do a task:
o CPU
o memory and
o files.
• The resources are allocated to process
o when the process is created or
o while the process is running.
• When the process terminates, the OS reclaims all the reusable resources.
• A program by itself is not a process;
o A program is a passive entity (such as the contents of a file stored on disk).
o A process is an active entity.
• Two types of process:
o Single-threaded process has one PC(program counter) which specifies location of the next
instruction to be executed.
o Multi-threaded process has one PC per thread which specifies location of next instruction to
execute in each thread

Memory Management
• The OS is responsible for the following activities:
o Keeping track of which parts of memory are currently being used and by whom
o Deciding which processes are to be loaded into memory when memory space becomes
available
o Allocating and de-allocating memory space as needed.
• Main memory is the array of bytes ranging from hundreds to billions.
• Each byte has its own address.
• The CPU
o reads instructions from main memory during the instruction-fetch cycle.
o reads/writes data from/to main-memory during the data-fetch cycle.
• To execute a program:
o The program will be
 loaded into memory and
 mapped to absolute addresses.
o Then, program accesses instructions & data from memory by generating absolute addresses.
o Finally, when program terminates, its memory-space is freed.
• To improve CPU utilization, keep several programs will be kept in memory
• Selection of a memory-management scheme depends on hardware-design of the system.
Storage Management
• File-System Management
• Mass-Storage Management
• Caching

File System Management


• The OS is responsible for following activities:
o Creating and deleting files.
o Creating and deleting directories.
o Supporting primitives for manipulating files & directories.
o Mapping files onto secondary storage.
o Backing up files on stable (non-volatile) storage media.
• Computer stores information on different types of physical
media. For ex: magnetic disk, optical disk.
• Each medium is controlled by a device (e.g. disk drive).
• The OS
o maps files onto physical media and
o accesses the files via the storage devices
• File is a logical collection of related information.
• File consists of both program & data.
• Data files may be numeric, alphabets or binary.
• When multiple users have access to files, access control (read, write) must be specified.

Mass Storage Management


• The OS is responsible for following activities:
o Free-space management
o Storage allocation and
o Disk scheduling.
• Usually, disks used to store
o data that does not fit in main memory or
o data that must be kept for a “long” period of time.
• Most programs are stored on disk until loaded into memory.
• The programs include
o compilers
o word processors and
o editors.
• The programs use the disk as both the source and destination of their processing.
• Entire speed of computer operation depends on disk and its algorithms.

Caching
• Caching is an important principle of computer systems.
• Information is normally kept in some storage system (such as main memory).
• As it is used, it is copied into a faster storage system called as the cache on a temporary basis.
• When we need a particular piece of information:
o We first check whether the information is in the cache.
o If information is in cache, we use the information directly from the cache.
o If information is not in cache, we use the information from the source, putting a copy in the
cache under the assumption that we will need it again soon.
• In addition, internal programmable registers, such as index registers, provide high-speed cache for
main memory.
• The compiler implements the register-allocation and register-replacement algorithms to decide which
information to keep in registers and which to keep in main memory.
• Most systems have an instruction cache to hold the instructions expected to be executed next.
• Most systems have one or more high-speed data caches in the memory hierarchy
• Because caches have limited size, cache management is an important design problem
• Careful selection of cache size & of a replacement policy can result in greatly increased performance

I/O Systems
• The OS must hide peculiarities of hardware devices from users.
• In UNIX, the peculiarities of I/O devices are hidden from the bulk of the OS itself by the I/O
subsystem.
• The I/O subsystem consists of
o A memory-management component that includes buffering, caching, and spooling.
o A general device-driver interface.
o Drivers for specific hardware devices.
• Only the device driver knows the peculiarities of the specific device to which it is assigned.

Protection and Security


• Protection is a mechanism for controlling access of processes or users to resources defined by OS.
• This mechanism must provide
o means for specification of the controls to be imposed and
o means for enforcement.
• Protection can improve reliability by detecting latent errors at the interfaces between subsystems.
• Security means defense of the system against internal and external attacks.
• The attacks include
o viruses and worms
o DOS(denial-of-service)
o identity theft.
• Protection and security require the system to be able to distinguish among all its users.
• User identities (user IDs) include name and associated number, one per user.
o User IDs are associated with all files (or processes) of that user to determine access control. 2.
Group identifier (group ID) allows set of users to be defined and controls managed, then also
associated with each process, file.

Distributed System
• This is a collection of physically separate, possibly heterogeneous computer-systems.
• The computer-systems are networked to provide the users with access to the various resources.
• Access to a shared resource increases
o computation speed
o functionality
o data availability and
o reliability
• A network is a communication path between two or more systems.
• Networks vary by the
o protocols used
o distances between nodes and
o transport media.
• Common network protocol are
o TCP/IP
o ATM.
• Networks are characterized based on the distances between their nodes.
o A local-area network (LAN) connects computers within a building.
o A wide-area network (WAN) usually links buildings, cities, or countries.
o A metropolitan-area network (MAN) could link buildings within a city.
• The media to carry networks are equally varied. They include
o copper wires,
o fiber strands, and
o wireless transmissions.

Special Purpose Systems


• Real-Time Embedded Systems
• Multimedia Systems
• Handheld Systems

Real-Time Embedded Systems


• Embedded computers are the most prevalent form of computers in existence.
• These devices are found everywhere, from car engines and manufacturing robots to VCRs and
microwave ovens.
• They tend to have very specific tasks.
• The systems they run on are usually primitive, and so the operating systems provide limited features.
• Usually, they prefer to spend their time monitoring & managing hardware devices such as
o automobile engines and
o robotic arms.
• Embedded systems almost always run real-time operating systems.
• A real-time system is used when rigid time requirements have been placed on the operation of a
processor.

Multimedia Systems
• Multimedia data consist of audio and video files as well as conventional files.
• These data differ from conventional data in that multimedia data must be delivered(streamed)
according to certain time restrictions.
• Multimedia describes a wide range of applications. These include
o audio files such as MP3
o DVD movies
o video conferencing
o live webcasts of speeches

Handheld Systems
• Handheld systems include
o PDAs and
o cellular telephones.
• Main challenge faced by developers of handheld systems: Limited size of devices.
• Because of small size, most handheld devices have a
o small amount of memory,
o slow processors, and
o small display screens.
Computing Environments
• Traditional Computing
• Client-Server Computing
• Peer-to-Peer Computing
• Web-Based Computing

Traditional Computing
• Used in office environment:
o PCs connected to a network, with servers providing file and print services.
• Used in home networks:
o At home, most users had a single computer with a slow modem.
o Some homes have firewalls to protect their networks from security breaches.
• Web technologies are stretching the boundaries of traditional computing.
o Companies establish portals, which provide web accessibility to their internal servers.
o Network computers are terminals that understand web computing.
o Handheld PDAs can connect to wireless networks to use company's web portal.
• Systems were either batch or interactive.
• Batch system processed jobs in bulk, with predetermined input.
• Interactive systems waited for input from users.

Client-Server Computing
• Servers can be broadly categorized as (Figure
1.10): 1. Compute servers and 2. File servers
• Compute-server system provides an interface to which a client can send a request to perform an
action (for example, read data).
o In response, the server executes the action and sends back results to the client. File-server
system provides a file-system interface where clients can create, read, and delete files.
o For example: web server that delivers files to clients running web browsers.

Figure 1.10 General structure of a client–server system.


Peer-to-Peer Computing
• All nodes are considered peers, and each may act as either a client or a server(Figure 1.11).
• Advantage:
o In a client-server system, the server is a bottleneck;
o but in a peer-to-peer system, services can be provided by several nodes distributed
throughout the network.
• A node must first join the network of peers.
• Determining what services are available is done in one of two general ways:
o When a node joins a network, it registers its service with a centralized lookup service on the
network.
 Any node desiring a specific service first contacts this centralized lookup service to
determine which node provides the service.
o A peer broadcasts a request for the service to all other nodes in the network. The node (or
nodes) providing that service responds to the peer.

Figure 1.11 Peer-to-peer system with no centralized service.

Web Based Computing


• This includes
o PC
o handheld PDA &
o cell phones
• Load balancer is a new category of devices to manage web traffic among similar servers.
• In load balancing, network connection is distributed among a pool of similar servers.
• More devices becoming networked to allow web access
• Use of operating systems like Windows 95, client-side, have evolved into Linux and Windows XP,
which can be clients and servers
 UNIT 1(CONT.): SYSTEM STRUCTURES

Operating System Services


• An OS provides an environment for the execution of programs.
• It provides services to
o programs and
o users.

Figure 1.12 A view of OS services

• Common functions helpful to the user are (Figure 1.12):


User Interface
• Almost all OS have a user-interface (UI).
• Different interfaces are:
o CLI (Command line Interface)
 This uses
 text commands and
 method for entering the text commands.
o Batch interface
o Commands & directives to control those commands are entered into files, and those files
are executed.
o GUI (Graphical User Interface)
o The interface is a window-system with a pointing-device to
 direct I/0
 choose from menus and
 make selections.
• Program Execution
• The system must be able to
o load a program into memory and
o run the program.
• The program must be able to end its execution, either normally or abnormally.
• I/O Operations
• The OS must provide a means to do I/O operations because users cannot control I/O devices directly.
• For specific devices, special functions may be desired (ex: to blank CRT screen).
File-system Manipulation
• Programs need to
o read & write files (or directories)
o create & delete files
o search for a given file and
o allow or deny access to files.

Communications
• In some situations, one process needs to communicate with another process.
• Communications may be implemented via
o Shared memory or
o Message passing
• In message passing, packets of information are moved between processes by OS.
Error Detection
• Errors may occur in
 CPU & memory-hardware (ex: power failure)
 I/O devices (ex: lack of paper in the printer) and
 user program (ex: arithmetic overflow)
o For each type of error, OS should take appropriate action to ensure correct & consistent
computing.
• Common functions for efficient operation of the system are:
 Resource Allocation
• When multiple users are logged on the system at the same time, resources must be allocated to each of
them.
• The OS manages different types of resources.
• Some resources (say CPU cycles) may have special allocation code.
 Other resources (say I/O devices) may have general request & release code.
 Accounting
• We want to keep track of
o which users use how many resources and
o which kinds of resources.
• This record keeping may be used for
o accounting (so that users can be billed) or
o gathering usage-statistics.
 Protection
• When several separate processes execute concurrently, it should not be possible for one process
to interfere with the others or with the OS itself.
• Protection involves ensuring that all access to resources is controlled.
• Security starts with each user having authenticated to the system by means of a password.

• User Operating System Interface


• Two ways that users interface with the OS:
o Command Interpreter (Command-line interface)
o Graphical User Interface (GUI)
Command Interpreter
• Main function:
o To get and execute the next user-specified command (Figure 1.13).
• The commands are used to manipulate files i.e. create, copy, print, execute, etc.
• Two general ways to implement:
o Command interpreter itself contains code to execute command.
o Commands are implemented through system programs. This is used by UNIX.
Graphical User Interfaces
• No entering of commands but the use of a mouse-based window and menu system (Figure 1.14).
• The mouse is used to move a pointer to the position of an icon that represents
o file
o program or
o folder
• By clicking on the icon, the program is invoked.

Figure 1.13 The Bourne shell command interpreter in Solaris 10.

Figure 1.14 The iPad touchscreen

System Calls
• These provide an interface to the OS services.
• These are available as routines written in C and C++.
• The programmers design programs according to an
API. (API=application programming interface).
• The API
o defines a set of functions that are available to the programmer (Figure 1.15).
o includes the parameters passed to functions and the return values.
• The functions that make up an API invoke the actual system-calls on behalf of the programmer.
• Benefits of API:
o Program portability.
o Actual system-calls are more detailed (and difficult) to work with than the API available to the
programmer.
• Three general methods are used to pass parameters to the OS:
o 1, via registers.
• Using a table in memory & the address is passed as a parameter in a register (Figure 1.16).
• The use of a stack is also possible where parameters are pushed onto a stack and popped off the stack
by the OS.
• Using a stack where parameters are
o pushed onto a stack and
o popped off the stack.

Figure 1.15 Example of how system calls are used.

Figure 1.16 Passing of parameters as a table.


• Types of System Calls
• Process control
• File management
• Device management
• Information maintenance
• Communications

• Process Control
• System calls used:
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
• A running program needs to be able to halt its execution either normally (end) or abnormally (abort).
• If program runs into a problem, error message may be generated and dumped into a file.
o This file can be examined by a debugger to determine the cause of the problem.
• The OS must transfer control to the next invoking command interpreter.
o Command interpreter then reads next command.
o In interactive system, the command interpreter simply continues with next command.
o In GUI system, a pop-up window will request action from user.
• How to deal with new process?
• A process executing one program can load and execute another program.
• Where to return control when the loaded program
terminates? The answer depends on the existing program:
o If control returns to the existing program when the new program terminates, we must save the
memory image of the existing program. (Thus, we have effectively created a mechanism for
one program to call another program).
o If both programs continue concurrently, we created a new process to be multiprogrammed.
• We should be able to control the execution of a process. i.e. we should be able to determine and reset
the attributes of a process such as:
o → job's priority or
o maximum execution time
• We may also want to terminate process that we created if we find that it
o is incorrect or
o is no longer needed.
• We may need to wait for processes to finish their execution.
o We may want to wait for a specific event to occur.
• The processes should then signal when that event has occurred.

File Management
• System calls used:
o create file, delete file
o open, close
o read, write, reposition
o get file attributes, set file attributes
• Working procedure:
o We need to create and delete files.
o Once the file is created,
 we need to open it and to use it.
 we may also read or write.
o Finally, we need to close the file.
• We need to be able to
o determine the values of file-attributes and
o reset the file-attributes if necessary.
• File attributes include
o file name
o file type
o protection codes and
o accounting information.

Device Management
• System calls used:
o request device, release device;
o read, write, reposition;
o get device attributes, set device attributes;
o logically attach or detach devices.
• A program may need additional resources to execute.
• Additional resources may be
o memory
o tape drives or
o files.
• If the resources are available, they can be granted, and control can be returned to the user program;
o If the resources are unavailable, the program may have to wait until sufficient resources are
available.
• Files can be thought of as virtual devices. Thus, many of the system calls used for files are also used
for devices.
• In multi-user environment,
o We must first request the device, to ensure exclusive use of it.
o After we are finished with the device, we must release it.
• Once the device has been requested (and allocated), we can read and write the device.
• Due to lot of similarity between I/O devices and files, OS (like UNIX) merges the two into a
combined file-device structure.
• UNIX merges I/O devices and files into a combined file-device structure.

• Information Maintenance
• System calls used:
o get time or date, set time or date
o get system data, set system data
o get process, file, or device attributes
o set process, file, or device attributes
• Many system calls exist simply for the purpose of transferring information between the user program
and the OS.
o For ex,
 Most systems have a system call to return
 current time and
 current date.
 Other system calls may return information about the system, such as
 number of current users
 version number of the OS
 amount of free memory or disk space.
 The OS keeps information about all its processes, and there are system calls to access
this information.

Communication
• System calls used:
o create, delete communication connection
o send, receive messages
o transfer status information
o attach or detach remote devices
• Two models of communication.
o Message-passing model and 2) Shared Memory Model
• Message Passing Model
• Information is exchanged through an IPC provided by OS.
o (IPC=inter process communication).
• Steps for communication:
o Firstly, a connection must be opened using open connection system-call.
o Each computer has a host-name, such as an IP name.
o Similarly, each process has a process-name, which is translated into an equivalent identifier.
The get hostid & get processid system-calls do this translation.
o Then, identifiers are passed to the open and close system-calls.
o The recipient-process must give its permission for communication to take place with an
accept connection system-call.
o (The processes that will be receiving connections are called daemons processes).
o Daemon processes
 execute a wait for connection system-call and
 are awakened when a connection is made.
o Then, client & server exchange messages by read message and write message system calls.
o Finally, the close connection system-call terminates the communication.
• Advantages:
o Useful when smaller numbers of data need to be exchanged.
o It is also easier to implement than is shared memory.
Shared Memory Model
• Processes use map memory system-calls to gain access to regions of memory owned by other
processes.
• Several processes exchange information by reading and writing data in the shared memory.
• The shared memory
o is determined by the processes and
o are not under the control of OS.
• The processes are also responsible for ensuring that they are not writing to the same location
simultaneously.
• Advantage:
o Shared memory allows maximum speed and convenience of communication,
• Disadvantage:
o Problems exist in the areas of protection and synchronization.

System Programs
• They provide a convenient environment for program development and execution.
o (System programs also known as system utilities).
• They can be divided into these categories:
• Six categories of system-programs:
o File Management
• These programs manipulate files i.e. create, delete, copy, and rename files.
o Status Information
• Some programs ask the system for
o date (or time)
o amount of memory(or disk space) or
o no. of users.
• These information is then printed to the terminal (or output-device or file).
• File Modification
• Text editors can be used to create and modify the content of files stored on disk.
• Programming Language Support
• Compilers, assemblers, and interpreters for common programming-languages (such as C,
o C++) are provided to the user.
• Program Loading & Execution
o The system may provide
o absolute loaders
o relocatable loaders
o linkage editors and
o overlay loaders.
• Debugging-systems are also needed.
• Communications
o These programs are used for creating virtual connections between
 processes
 users and
 computer-systems.
o They allow users to
 browse web-pages
 send email or
 log-in remotely.
• Most OSs are supplied with programs that
• solve common problems or
• perform common operations. Such programs include
o web-browsers
o word-processors
o spreadsheets and
o games.
o These programs are known as application programs.

Operating System Design & Implementation


Design Goals
• The first problem in designing a system is to
o define goals and
o define specifications.
• The design of the system will be affected by
o choice of hardware and
o type of system such as
 batch or time shared
 single user or multiuser
• Two basic groups of requirements:
• User goals and 2. System goals
User Goals
• The system should be
o convenient to use
o easy to learn and to use
o reliable, safe, and fast.
System Goals
• The system should be
o easy to design
o implement, and maintain
o flexible, reliable, error free, and efficient.

Mechanisms & Policies


• Mechanisms determine how to do something.
• Policies determine what will be done.
• Separating policy and mechanism is important for flexibility.
• Policies change over time; mechanisms should be general.

Implementation
• OS's are nowadays written in higher-level languages like C/C++
• Advantages of higher-level languages:
o Faster development and
o OS is easier to port.
• Disadvantages of higher-level languages:
o Reduced speed and
o Increased storage requirements.

• Operating System Structure


• Simple Structure
• Layered Approach
• Microkernels
• Modules

• Simple Structure
• These OSs are small, simple, and limited system.
• For example: MS-DOS and UNIX.
o MS-DOS

was written to provide the most functionality in the least space.
Disadvantages:
 It was not divided into modules carefully (Figure 1.17).
 The interfaces and levels of functionality are not well separated.

 Figure 1.17 MS-DOS layer structure


• UNIX was initially limited by hardware functionality. 
Two parts of UNIX (Figure 1.18):
o Kernel and
• System programs.
 The kernel is further separated into a series of interfaces and device
drivers.
 Everything below the system-call interface and above the physical
hardware is the kernel.  The kernel provides following functions
through system calls:
 → file system
 → CPU scheduling and
 → memory management.
• Disadvantage:
o Difficult to enhance, as changes in one section badly affects other areas.

Figure 1.18 Traditional UNIX system structure


Layered Approach
• The OS is divided into a number of layers.
• Each layer is built on the top of another layer.
• The bottom layer is the hardware.
o The highest is the user interface (Figure 1.19).
• A layer is an implementation of an abstract-
object. i.e. The object is made up of
 data and
 operations that can manipulate the data.
• The layer consists of a set of routines that can be invoked by higher-layers.
• Higher-layer
o does not need to know how lower-layer operations are implemented
o needs to know only what lower-layer operations do.
• Advantage:
o Simplicity of construction and debugging.
• Disadvantages:
o Less efficient than other types.
o Appropriately defining the various layers.(‘.’ a layer can use only lower-layers,
careful planning is necessary).

Figure 1.19 A layered OS


MicroKernels
• Main function:
o To provide a communication facility between
 client program and
 various services running in user-space.
• Communication is provided by message passing (Figure 1.20).
• All non-essential components are
o removed from the kernel and
o implemented as system- & user-programs.
• Advantages:
 Ease of extending the OS. (New services are added to user space w/o modification of
kernel).
 Easier to port from one hardware design to another.
 Provides more security & reliability.(If a service fails, rest of the OS remains
untouched.).
 Provides minimal process and memory management.
o Disadvantage:
 Performance decreases due to increased system function overhead.

Figure 1.20 Architecture of a typical microkernel


Modules
• The kernel has
o set of core components and
o dynamic links in additional services during boot time( or run time).
• Seven types of modules in the kernel (Figure 1.21):
• Scheduling classes
• File systems
• Loadable system calls
• Executable formats
• STREAMS modules
• Miscellaneous
• Device and bus drivers
• The top layers include
o application environments and
o set of services providing a graphical interface to applications.
• Kernel environment consists primarily of
o Mach microkernel and
o BSD kernel.
• Mach provides
o memory management;
o support for RPCs & IPC and
o thread scheduling.
• BSD component provides
o BSD command line interface
o support for networking and file systems and
o implementation of POSIX APIs
• The kernel environment provides an I/O kit for development of
o device drivers and
o dynamic loadable modules (which Mac OS X refers to as kernel extensions).

Figure 1.21 Solaris loadable modules


Virtual Machines
• Main idea:
• To abstract hardware of a single computer into several different execution environments.
• An OS creates the illusion that a process has
o own processor &
o own (virtual) memory.
• The virtual-machine provides
o an interface that is identical to the underlying hardware (Figure 1.22).
o a (virtual) copy of the underlying computer to each process.

Figure 1.22 System models, (a) Nonvirtual machine, (b) Virtual machine.

• Problem: Virtual-machine software itself will need substantial disk space to provide virtual
memory. Solution: provide virtual disks that are identical in all respects except size.
• Advantages:
 Complete protection of the various system resources.
 It is a perfect vehicle for OS’s R&D.
• Disadvantage:
o Difficult to implement due to effort required to provide an exact duplicate to underlying
machine.

Operating System Generation


• OS is designed to run on any of a class of machines.
o However, the system must be configured for each specific computer site
 SYSGEN is used for configuring a system for each specific computer site
 SYSGEN program must determine:
o What CPU will be used?
o How will boot disk be formatted?
o How much memory is available?
o What devices are available?
o What OS options are desired?
 A system-administrator can use the above information to modify a copy of the source code of the OS

System Boot
 Booting means starting a computer by loading the kernel.
 Bootstrap program is a code stored in ROM.
 The bootstrap program
o locates the kernel
o loads the kernel into main memory and
o starts execution of kernel.
 OS must be made available to hardware so hardware can start it.

You might also like