28
Operating-System Structures Operating System Services User Operating System Interface System Calls Types of System Calls System Programs System Programs Operating System Design and Implementation Operating System Structure Virtual Machines Operating System Generation System Boot Loganathan R, CSE , HKBKCE 1

2 operating system structures

Embed Size (px)

DESCRIPTION

Operating System Structures

Citation preview

Page 1: 2 operating system structures

Operating-System Structures

Operating System Services

User Operating System Interface

System Calls

Types of System Calls

System Programs System Programs

Operating System Design and Implementation

Operating System Structure

Virtual Machines

Operating System Generation

System Boot

Loganathan R, CSE , HKBKCE1

Page 2: 2 operating system structures

1. Operating System Services• One set of operating-system services provides functions that are helpful to the user:

– User interface - Almost all operating systems have a user interface (UI)Command-Line (CLI), Batch Interface & Graphics User Interface (GUI)

– Program execution - Load a program into memory and to run that program, endexecution, either normally or abnormally (indicating error)

– I/O operations - A running program may require I/O, which may involve a file oran I/O device.

– File-system manipulation - Programs need to read and write files anddirectories, create and delete them, search them, list file Information,directories, create and delete them, search them, list file Information,permission management.

– Communications – Between process in the same or different computer viashared memory or message passing

– Error Detection - Errors may occur in the CPU and memory hardware ( memoryerror or power failure), in I/O devices (parity error on tape, a connection failureon a network, or lack of paper in the printer) and in the user program(arithmetic overflow, illegal memory location access, or a too-great use of CPUtime)

Loganathan R, CSE , HKBKCE2

Page 3: 2 operating system structures

1. Operating System Services Contd..

• Another set of OS functions exists for ensuring the efficient operation of thesystem itself via resource sharing

– Resource allocation - When multiple users or multiple jobs runningconcurrently, resources must be allocated to each of them

• Many types of resources - Some (such as CPU cycles, main memory, andfile storage) may have special allocation code, others (such as I/Odevices) may have general request and release code.

– Accounting - To keep track of which users use how much and what kinds ofcomputer resources

– Protection and security - The owners of information stored in a multiuser or– Protection and security - The owners of information stored in a multiuser ornetworked computer system may want to control use of that information,concurrent processes should not interfere with each other

• Protection involves ensuring that all access to system resources iscontrolled

• Security of the system from outsiders requires user authentication,extends to defending external I/O devices from invalid access attempts

• If a system is to be protected and secure, precautions must be institutedthroughout it. A chain is only as strong as its weakest link.

Loganathan R, CSE , HKBKCE 3

Page 4: 2 operating system structures

2.User Operating System Interface• 2.1 Command Interpreter / CLI

• Implemented in kernel, sometimes by systems program

• Function of the command interpreter is to get and executethe user-specified command.

• Multiple command interpreters to choose from theinterpreters are known as shells

• Example :Bourne shell, C shell, Bourne-Again shell, the Korn• Example :Bourne shell, C shell, Bourne-Again shell, the Kornshell

• Command Interpreter Implementation• Command interpreter itself contains the code to execute the

command

• Through system programs – uses the command to identify a file tobe loaded into memory and executed

• Example rm file.txt

Loganathan R, CSE , HKBKCE 4

Page 5: 2 operating system structures

User Operating System Interface Cntd..

2.2 Graphical User Interfaces User-friendly desktop metaphor interface◦ Usually mouse, keyboard, and monitor

◦ Icons represent files, programs, actions, etc

◦ Various mouse buttons over objects in the interface cause variousactions (provide information, options, execute function, opendirectory (known as a folder)directory (known as a folder)

◦ Invented at Xerox PARC

Many systems now include both CLI and GUI interfaces◦ Microsoft Windows is GUI with CLI “command” shell

◦ Apple Mac OS X as “Aqua” GUI interface with UNIX kernelunderneath and shells available

◦ Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)

Loganathan R, CSE , HKBKCE 5

Page 6: 2 operating system structures

3. System Calls Programming interface to the services provided by the OS Typically written in a high-level language (C or C++) Example of how system calls are used to copy the files

Loganathan R, CSE , HKBKCE 6

Page 7: 2 operating system structures

Application Programming Interface(API) System calls are mostly accessed by programs via a high-

level Application Program Interface (API) rather thandirect system call use

• API specifies a set of functions that are available to anapplication programmer, including the parameters that arepassed

Three most common APIs are Win32 API for Windows,POSIX API for POSIX-based systems (including virtually allPOSIX API for POSIX-based systems (including virtually allversions of UNIX, Linux, and Mac OS X), and Java API forthe Java virtual machine (JVM)

Why use APIs rather than system calls?• Program portability• Actual system calls can be more detailed and difficult to

work with than the API

Loganathan R, CSE , HKBKCE 7

Page 8: 2 operating system structures

System Call Implementation• Programming languages provides a system-call interface that serves as the

link to system calls made available by the OS• System-call interface intercepts function calls in the API and invokes the

necessary system call within the OS• System-call interface maintains a table indexed according to these numbers

associated with each system call• The system call interface invokes intended system call in OS kernel and

returns status of the system call and any return values

Loganathan R, CSE , HKBKCE8

Page 9: 2 operating system structures

System Call Parameter Passing• Registers• Parameters stored in a block, or table, in memory, and address of block

passed as a parameter in a register (Linux and Solaris) as shown• Parameters placed, or pushed, onto the stack by the program and popped off

the stack by the operating system– Block and stack methods do not limit the number or length of parameters

being passed

Loganathan R, CSE , HKBKCE 9

Page 10: 2 operating system structures

4. Types of System Calls4.1 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

Loganathan R, CSE , HKBKCE10

Multitasking: FreeBSDrunning multiple programs

Single Tasking: MS-DOS execution,(a) At system startup, (b) Running aprogram

fork()exec()exit()

Page 11: 2 operating system structures

4. Types of System Calls Contd

4.2 File management• File – create, delete, open, close, read, write, reposition• Get / set file attributes

4.3 Device managementThe various resources controlled by the OS can be thought of as devices• Device – request, release, read, write, reposition• get / set device attributes • Logically attach or detach devices

4.4 Information maintenanceTransferring information between the user program and the OSTransferring information between the user program and the OS

and keeps information about all its processes and system calls• get / set – time or date • get / set system data• get / set – process, file or device attributes

4.5 CommunicationsInter-process communication Models :

Message passing model & Shared-memory model• Create, delete communication connection • Send, receive messages• Transfer status information • Attach or detach remote devices

Loganathan R, CSE , HKBKCE11

Page 12: 2 operating system structures

5. System Programs System programs provide a convenient environment for

program development and execution. Categories◦ File management - create, delete, copy, rename, print, dump, list,

and manipulate files and directories◦ Status information - date, time, available memory or disk space, no

of users, performance, logging, and debugging information◦ File modification - text editors to create and modify the content of

files, search contents of files.◦ Programming language support - Compilers, assemblers, debuggers◦ Programming language support - Compilers, assemblers, debuggers

and interpreters◦ Program loading and execution - absolute loaders, relocatable

loaders, linkage editors, overlay loaders and debuggers◦ Communications - Creating virtual connections among processes,

users, and computer systems◦ System utilities Application programs - web browsers, word

processors , text formatters, spreadsheets, database systems,compilers, plotting and statistical-analysis packages and games

Most users’ view of the operation system is defined bysystem programs, not the actual system calls

Loganathan R, CSE , HKBKCE12

Page 13: 2 operating system structures

6. OS Design and Implementation Design and Implementation of OS not “solvable”,

but some approaches have proven successful 6.1 Design Goals

– The design of the system is affected by the choice ofhardware and the type of system: batch, time shared,single user, multiuser, distributed, real time, or generalpurposepurpose

– The requirement can be divided to User goals andSystem goals◦ User goals – operating system should be convenient to use,

easy to learn, reliable, safe, and fast◦ System goals – operating system should be easy to design,

implement, and maintain, as well as flexible, reliable, error-free, and efficient

Loganathan R, CSE , HKBKCE 13

Page 14: 2 operating system structures

6. OS Design and Implementation Contd..

6.2 Mechanisms and Policies• Mechanisms determine how to do something, policies decide

what will be done– Example : timer construct is a mechanism for ensuring CPU

protection(loop), but deciding how long the timer is to be set fora particular user is a policy decision

– The separation of policy from mechanism is a very importantprinciple, it allows maximum flexibility if policy decisions are tobe changed laterbe changed later

6.3 Implementation• Traditionally, written in assembly language, now C or C++• Advantages of using a higher-level language

– Faster Coding , more compact, easier to understand and debug– Easier to port—to move to some other hardware

• Disadvantages of using a higher-level language– Reduced speed and increased storage requirements

Loganathan R, CSE , HKBKCE 14

Page 15: 2 operating system structures

7. Operating-System Structure• How OS components are

interconnected and melded into akernel.

7.1 Simple Structure• Started as small, simple, and limited

systems and then grown beyond theiroriginal scope

• Example : MS-DOS – written to• Example : MS-DOS – written toprovide the most functionality in theleast space– Not divided into modules– Although MS-DOS has some

structure, its interfaces and levelsof functionality are not wellseparated

Loganathan R, CSE , HKBKCE15

MS-DOS layer structure

Page 16: 2 operating system structures

7. Operating-System Structure Contd…

• 7.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 H/W The highest (layer N) is the UI.– A layer is an implementation of an abstract object consists of data

structures and a set of routines that can be invoked by higher-level layers

•Advantage• Simplicity of construction and

debugging

Loganathan R, CSE , HKBKCE16

debugging• Each layer is implemented with only

those operations provided by lowerlevel layers

• The first layer can be debuggedwithout any concern for the rest of thesystem

• Correct functioning of first layer canbe assumed while the second layer isdebugged, and so on

Page 17: 2 operating system structures

Example: UNIX UNIX – limited by hardware functionality, the original UNIX operating system

had limited structuring. The UNIX OS consists of two separable parts◦ Systems programs◦ The kernel Consists of everything below the system-call interface and above the

physical hardware Provides the file system, CPU scheduling, memory management, and other

operating-system functions; a large number of functions for one level

Loganathan R, CSE , HKBKCE17

Page 18: 2 operating system structures

7. Operating-System Structure Contd…

7.3 Microkernels• Structures the OS by removing all nonessential

components from the kernel and implementingthem as system and user-level programs.

Communication takes place between user modulesusing message passing

Benefits:◦Benefits:◦ Easier to extend a microkernel◦ Easier to port the operating system to new architectures◦ More reliable (less code is running in kernel mode)◦ More secure

Detriments:◦ Performance overhead of user space to kernel space

communication

Loganathan R, CSE , HKBKCE 18

Page 19: 2 operating system structures

7. Operating-System Structure Contd…

7.4 Modules– Uses object-oriented approach– Each core component is separate– Each talks to the others over known interfaces– Each is loadable as needed within the kernel– a core kernel with seven types of loadable kernel modules

Loganathan R, CSE , HKBKCE 19

Page 20: 2 operating system structures

Mac OS X Structure(Darwin)• Uses a hybrid structure – layered technique with one layer consists of the Mach

microkernel.• Top layers include application environments and a set of services providing a

graphical interface to applications• Below these layers is the kernel consists primarily of the Mach microkernel and

the BSD kernel• Mach provides m/y mgmt, support RPC and IPC facilities, including message

passing and thread scheduling• BSD component provides a BSD CLI, support for networking and file systems, and

an implementation of POSIX APIs, including Pthreads

Loganathan R, CSE , HKBKCE 20

an implementation of POSIX APIs, including Pthreads

Page 21: 2 operating system structures

8. Virtual Machines• A virtual machine takes the layered approach to its logical

conclusion.• It abstracts hardware of a single computer into several different

execution environments i.e. creates illusion of separateexecution environment is running its own private computer.

• 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)each executing on its own processor with its own (virtual)memory

• The resources of the physical computer are shared to create thevirtual machines

• A major difficulty is disk systems, solved using Virtual disks(minidisks in IBM)

• Users are given their own virtual machines and they can run anyof the operating systems or software packages that are available

Loganathan R, CSE , HKBKCE 21

Page 22: 2 operating system structures

8. Virtual Machines Cont…

Loganathan R, CSE , HKBKCE 22

Non-virtual Machine Virtual Machine

Page 23: 2 operating system structures

• 8.1 Implementation– Much work is required to provide an exact duplicate of

the underlying machine– A virtual user mode and a virtual kernel mode, both of

which run in a physical user mode.– Transfer from user mode to kernel mode on a real

machine also cause a transfer from virtual user mode to

8. Virtual Machines Cont…

machine also cause a transfer from virtual user mode tovirtual kernel mode on a virtual machine

– A system call in virtual user mode will cause a transfer tothe virtual-machine monitor, it can simulate the effect ofthe system call by changing the register and programcounter for the virtual machine

– The real I/O may take100 milliseconds, the virtual I/Omight take less time(spooled) or more time(interpreted).

Loganathan R, CSE , HKBKCE 23

Page 24: 2 operating system structures

• 8.2 Benefits– Complete protection of the various system resources– No direct sharing of resources and implementation

through• Share a minidisk and thus to share files through

software• Network of virtual machines over the virtual

8. Virtual Machines Cont…

• Network of virtual machines over the virtualcommunications network

– VM system is a perfect vehicle for OS research anddevelopment

– A virtual-machine system eliminates system developmenttime

• System must be stopped and taken out of use whilechanges are made and tested , this period is calledsystem development time

Loganathan R, CSE , HKBKCE 24

Page 25: 2 operating system structures

• 8.3 Examples– 8.3.1 Vmware

• Abstracts Intel 80X86 hardware into isolated virtual machines.• Runs as an application on host OS and allows concurrently

running several different guest operating systems asindependent virtual machines

8. Virtual Machines Cont…

25

Page 26: 2 operating system structures

• 8.3 Examples– 8.3. 2 The Java Virtual Machine– Java program consists of one or more classes, for each, the compiler

produces an architecture-neutral bytecode output (.class) file that willrun on any implementation of the JVM.

– JVMis a specification for an abstract computer

– consists of a class loader and a Java interpreter (or a fast just-in-time (JIT) compiler ) that executes the architecture-neutral bytecodes

8. Virtual Machines Cont…

26

Class loader

JavaInterpreter

Host systems(Windows, Linux, etc)

Java Program.class files

Java API.class files

Page 27: 2 operating system structures

• It is possible to design, code, and implement an operating systemspecifically for one machine at one site

• A processes of configuring or generating system for each specificcomputer site, is known as system generation (SYSGEN)

• The SYSGEN program reads from a given file, or asks the operator forthe specific configuration of the hardware system, or probes thehardware directly

• Once information is determined , a system administrator can use it

9. Operating-System Generation

• Once information is determined , a system administrator can use itto modify the source code of OS , then compile and the outputobject version is tailored to the system

• A slightly less tailored level modules are selected from aprecompiled library and linked together to form OS

• Other extreme, all the code is always part of the system, andselection occurs at execution time, rather than at compile or linktime.

• The major differences among these approaches are the size andgenerality 27

Page 28: 2 operating system structures

10. System Boot• Operating system must be made available to hardware so

hardware can start it• When power initialized on system, execution starts at a

predefined memory location (in ROM) where initial bootstrapprogram stored

• Small piece of code – bootstrap program or bootstraploader, locates the kernel, loads it into memory, and starts itsexecutionexecution

• Sometimes two-step process where simple boot block /bootstrap loader fetches a complex boot program, whichloads kernel

• A disk that has a boot partition is called a boot disk or systemdisk.

• Problem with ROM is that changing the bootstrap coderequires changing the ROM hardware chips which is resolvedusing erasable programmable read-only memory (EPROM)

Loganathan R, CSE , HKBKCE28