Modern Operating System · Preface It gives me an immense pleasure to come up with the first...

Preview:

Citation preview

Modern OperatingSystem

(As per the Syllabus 2012 - 13 of Mumbai University for B.Sc. - IT, Semester III)

Mrs. Jeba RoseletMCA, M Phil. (Computer Science)

Assistant Professor.Ramniranjan Jhunjhunwala College,

Ghatkopar (W), Mumbai, Maharashtra, India.

ISO 9001:2008 CERTIFIED

© AuthorNo part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by anymeans, electronic, mechanical, photocopying, recording and/or otherwise without the prior written permission of thepublisher.

First Edition : 2016

Published by : Mrs. Meena Pandey for Himalaya Publishing House Pvt. Ltd.,“Ramdoot”, Dr. Bhalerao Marg, Girgaon, Mumbai - 400 004.Phone: 022-23860170/23863863, Fax: 022-23877178E-mail: himpub@vsnl.com; Website: www.himpub.com

Branch Offices :New Delhi : “Pooja Apartments”, 4-B, Murari Lal Street, Ansari Road, Darya Ganj,

New Delhi - 110 002. Phone: 011-23270392, 23278631; Fax: 011-23256286Nagpur : Kundanlal Chandak Industrial Estate, Ghat Road, Nagpur - 440 018.

Phone: 0712-2738731, 3296733; Telefax: 0712-2721216Bengaluru : Plot No. 91-33, 2nd Main Road Seshadripuram, Behind Nataraja Theatre,

Bengaluru-560020. Phone: 08041138821, 9379847017, 9379847005.Phone: 080-22286611, 22385461, 4113 8821, 22281541

Hyderabad : No. 3-4-184, Lingampally, Besides Raghavendra Swamy Matham, Kachiguda,Hyderabad - 500 027. Phone: 040-27560041, 27550139

Chennai : New-20, Old-59, Thirumalai Pillai Road, T. Nagar, Chennai - 600 017.Mobile: 9380460419

Pune : First Floor, "Laksha" Apartment, No. 527, Mehunpura, Shaniwarpeth(Near Prabhat Theatre), Pune - 411 030. Phone: 020-24496323/24496333;Mobile: 09370579333

Lucknow : House No 731, Shekhupura Colony, Near B.D. Convent School, Aliganj,Lucknow - 226 022. Phone: 0522-4012353; Mobile: 09307501549

Ahmedabad : 114, “SHAIL”, 1st Floor, Opp. Madhu Sudan House, C.G. Road, Navrang Pura,Ahmedabad - 380 009. Phone: 079-26560126; Mobile: 09377088847

Ernakulam : 39/176 (New No: 60/251) 1st Floor, Karikkamuri Road, Ernakulam,Kochi – 682011. Phone: 0484-2378012, 2378016 Mobile: 09387122121

Bhubaneswar : 5 Station Square, Bhubaneswar - 751 001 (Odisha).Phone: 0674-2532129, Mobile: 09338746007

Kolkata : 108/4, Beliaghata Main Road, Near ID Hospital, Opp. SBI Bank,Kolkata - 700 010, Phone: 033-32449649, Mobile: 7439040301

DTP by : Nilima JadhavPrinted at : Rose Fine Art, Mumbai. On behalf of HPH.

Preface

It gives me an immense pleasure to come up with the first edition of the book ModernOperating Systems for S.Y.B.Sc. IT course started by University of Mumbai. This book will helpyou to understand the basics of operating system in general.

The chapters are arranged as such one will understand the concept clearly. The practice questionsat the end of each chapter will help you to cater all your need for this subject.

I am extremely grateful to our Principal Dr. Mrs. Usha Mukundan for her constant support andencouragement. I am also thankful to my colleagues and my family members for their valuablesuggestions and their extended support to write this book.

Special thanks to S.K. Shrivastav and staff of M/s Himalaya Publishing House Pvt. Ltd. for theireffort to make this book flawless, but as it happens with operating system a few obscure bugs mayremain.

I would appreciate to hear any constructive suggestion from students and teachers for improvingthis book in future.

Authors

SyllabusSubject: Modern Operating Systems

Course Code: USIT305

CLASS: B.SC (Information Technology) Semester – III

Unit – I Introduction to Operating Systems: OS and Computer System, Systemperformance, classes of OS, Batch processing, time-sharing,multiprocessing, real time, distributed and modern operating systems,Desktop Systems, Handheld Systems, Clustered Systems, Assemblers,Compilers and Interpreters, Linkers.

8 Lectures

Unit - II Operating System Structures: Operating System Services, UserOperating System Interface, System Calls, Types of System Calls,System Programs, Operating System Design and Implementation,Operating-System Structure, Virtual Machines, Operating SystemGeneration, System Boot.

8 Lectures

Unit - III Processes and Process Synchronization: Process Concept, ProcessScheduling, Scheduling Criteria, Scheduling Algorithms, Operations onProcesses, Interprocess Communication, Multithreading Models,Threading Issues, Thread Scheduling, Communication in Client-ServerSystems, The Critical Section Problem, Peterson’s Solution, Semaphores

8 Lectures

Unit - IV Memory Management: Memory management without swapping orpaging; Swapping, Virtual Memory, Page replacement algorithms,Modeling paging algorithms, Design issues for paging systems,segmentation.

8 Lectures

Unit - V File System Interface and Implementation: File Concept, File SystemMounting, Free Space Management, File Sharing, NFS, Mass-StorageStructure: Disk Structure, Disk Management, Swap Space Management,RAID Structure, Stable Storage Implementation. Deadlocks, Deadlockdetection and recovery, avoidance and prevention

8 Lectures

Unit - VI I/O System: Application I/O Interface, Transforming I/O Requests toHardware Operations, Streams, Performance.Protection and Security: Principles of Protection, Domain ofProtection, Access Matrix, Access Control, Capability-based Systems,Language-based Protection, The Security Problem, System and NetworkThreats, Implementing Security Defenses.

8 Lectures

PAPER PATTERNMax. Marks: 75 Time: 2½ Hrs

Instructions:1. All questions are compulsory.2. Attempt any TWO sub-questions from each question.3. Each sub-question is of 5 marks.

Q.1 Answer any TWO of the following: From unit 1 [10](a)(b)(c)(d)

Q.2 Answer any TWO of the following: From unit 2 [10](a)(b)(c)(d)

Q.3 Answer any TWO of the following: From unit 3 [10](a)(b)(c)(d)

Q.4 Answer any TWO of the following: From unit 4 [10](a)(b)(c)(d)

Q.5 Answer any TWO of the following: From unit 5 [10](a)(b)(c)(d)

Q.6 Answer any TWO of the following: From unit 6 [10](a)(b)(c)(d)

Q.7 Answer any THREE of the following: [15](a) From unit 1(b) From unit 2(c) From unit 3(d) From unit 4(e) From unit 5(f) From unit 6

ContentsSr. No. Name Page No.

1 Introduction to Operating System 1 – 9

2 System Program 10 – 14

3 Operating System Structures 15 – 28

4 Process Management 29 – 47

5 Threads and Process Synchronization 48 – 60

6 Memory Management 61 – 87

7 File System 88 – 123

8 Deadlock 124 – 133

9 I/O Systems 134 – 143

10 Protection and Security 144 – 157

Introduction to OperatingSystem

1

Structure: OS and Computer System

– Defining Operating System– Goals of Operating System

System Performance Classes of Operating System

– Batch Operating System– Time-sharing Operating Systems– Multiprocessor Operating System– Real Time Operating System (RTOS)– Distributed Operating System– Network Operating System– Desktop Systems– Handheld Systems– Clustered Systems– Modern Operating Systems

Practice Questions

OS AND COMPUTER SYSTEM

A computer system can be divided roughly into four components: the hardware, the operatingsystem, the application programs, and the users as shown in the figure 1.1 .The hardware—the centralprocessing unit (CPU), the memory, and the input/output (I/O) devices. It provides the basiccomputing resources for the system. The application programs—such as word processors,spreadsheets, compilers, and web browsers. It defines the ways in which these resources are used tosolve the users computing problems. The operating system controls and coordinates the use of thehardware among the various application programs for the various users.

2 Modern Operating System

A computer system has many resources that may be required to solve a problem: CPU time,memory space, file-storage space, I/O devices, and so on. The operating system acts as a resourceallocator A control program that manages the execution of user programs to prevent errors andimproper use of the computer. It controls the operation of I/O devices.

User1

User2

User3

Usern

compiler assembler text editor databasesystem

System and application programs

operating system

computerhardware

Fig. 1.1: Abstract view of the Components of a Computer System.

Defining Operating SystemAn operating System (OS) is an intermediary between users and computer hardware. It provides

users an environment in which a user can execute programs conveniently and efficiently.In technical terms, it is software which manages hardware. An operating System controls the

allocation of resources and services such as memory, processors, devices and information.Operating System can also be defined as Resource allocator: manages and allocates resources. Control program: controls the execution of user programs and operations of I/O devices. Kernel: the one program running at all times (all else being application programs).

Goals of Operating System Execute user programs and make solving user problems easier. Make the computer system convenient to use. Use the computer hardware in an efficient way

SYSTEM PERFORMANCE

A modern OS can service several user programs simultaneously. The OS achieves it byinteracting with the computer and user programs to perform several control functions. The CPUcontains a set of control registers whose contents govern its functioning.

3Introduction to Operating System

The program status word (PSW) is the collection of control registers of the CPU; we refer to eachcontrol register as a field of the PSW. A program whose execution was interrupted should be resumedat a later time. To facilitate this, the kernel saves the CPU state when an interrupt occurs.

The CPU state consists of the PSW and program-accessible registers, which we call general-purpose registers (GPRs). Operation of the interrupted program is resumed by loading back the savedCPU state into the PSW and GPRs.

The input-output system is the slowest unit of a computer; the CPU can execute millions ofinstructions in the amount of time required to perform an I/O operation. Some methods of performingan I/O operation require participation of the CPU, which wastes valuable CPU time. Hence the input-output system of a computer uses direct memory access (DMA) technology to permit the CPU and theI/O system to operate independently.

The operating system exploits this feature to let the CPU execute instructions in a program whileI/O operations of the same or different programs are in progress. This technique reduces CPU idletime and improves system performance.

CLASSES OF OPERATING SYSTEM

Operating systems are there from the very first computer generation. Operating systems keepevolving over the period of time. Following are few of the important types of operating system whichare most commonly used.

Operating System Class Period Primary Concern Key Concepts

Batch Processing Systems 1960s CPU idle time Automate transition between jobs

Time Sharing Systems 1970s Good response time Time-slice, round robin scheduling

Multiprocessing Systems 1980sMaster/Slave processorPriority

Symmetric/Asymmetricmultiprocessing

Real Time Systems 1980s Meeting time constraints Real-time scheduling

Distributed Systems 1990s Resource sharing Distributed control, transparency

Desktop Systems 1970s Good support to a single user Word processing, Internet access

Handheld Systems Late1980s

32-bit CPUs with protectedmode

Handle telephony, digital photography,and third party applications

Clustered SystemsEarly1980s

Low cost Ups, high speednetworks

Task scheduling, node failuremanagement

Batch Operating SystemBatch processing is a technique in which Operating System collects one program and data

together in a batch before processing starts. Operating system does the following activities related tobatch processing.

OS defines a job which has predefined sequence of commands, programs and data as asingle unit.

OS keeps a number of jobs in memory and executes them without any manual information. Jobs are processed in the order of submission i.e first come first serve (FCFS) fashion.

4 Modern Operating System

When job completes its execution, its memory is released and the output for the job getscopied into an output spool for later printing or processing.

The users of batch operating system do not interact with the computer directly. Each userprepares his job on an off-line device like punch cards and submits it to the computer operator. Tospeed up processing, jobs with similar needs are batched together and run as a group. Thus, theprogrammers leave their programs with the operator. The operator then sorts programs into batcheswith similar requirements.

Advantages of Batch Processing System Batch processing takes much of the work of the operator to the

computer. Increased performance as a new job get started as soon as the

previous job finishes

Disadvantages of Batch Processing System Lack of interaction between the user and job. CPU is often idle, because the speeds of the mechanical I/O

devices are slower than CPU Difficult to provide the desired priority.

Time-sharing operating systemsTime sharing is a technique which enables many people, located at various terminals, to use a

particular computer system at the same time. In Time-sharing system the processor's time is sharedamong multiple users simultaneously .

The main difference between Multiprogrammed Batch Systems and Time-Sharing Systems isthat, In case of Multiprogrammed Batch Systems, objective is to maximize processor use, whereas inTime-Sharing Systems objective is to minimize response time.

Multiple jobs are executed by the CPU by switching between them, and the switches occur sofrequently, that the user can receive an immediate response. For example, in a transaction processing,processor execute each user program in a short burst or quantum of computation. That is if n users arepresent, each user can get time quantum. When the user submits the command, the response time is infew seconds at the most.

Advantages of Timesharing operating systems Provide advantage of quick response. Avoids duplication of software. Reduces CPU idle time.

Disadvantages of Timesharing operating systems Problem of reliability. Security and integrity of user programs and data is questionable. Problem of data communication.

Operating system

Job 1

Job 2

Job 3

Job 4

Fig. 1.2: Memory Layout fora Simple Batch System

5Introduction to Operating System

Multiprocessor Operating SystemMultiprocessor Operating System uses two or more central processing units (CPU) within a

single computer system. These multiple CPUs are in a close communication, sharing the computer bus,memory and other peripheral devices. These systems are referred to as tightly coupled systems orparallel systems

These types of systems are used to process a large volume of data in a very high speed. Thesesystems are generally used in environment like satellite control, weather forecasting etc. The basicorganization of multiprocessing system is shown in fig. 1.3.

Fig. 1.3: Symmetric Multiprocessing Architecture.

Two variations of Multiprocessing Systems are(a) Symmetric multiprocessing (SMP)

Each processor runs an identical copy of the operating system. Many processes can run at once without performance deterioration. Most modern operating systems support SMP

(b) Asymmetric multiprocessing Each processor is assigned a specific task; master processor schedules and allocated

work to slave processors More common in extremely large systems

Advantages of the multiprocessing system Increased (throughput): By increasing the number of processors, we get more work done

in less time. Economical: Multiprocessor systems can cost less as they share peripherals, mass storage,

and power supplies Increased reliability: As the work are distributed properly among several processors, then

the failure of one processor will not halt the system, only slow it down. The ability tocontinue providing service proportional to the level of surviving hardware is called gracefuldegradation. Such systems are also called fault tolerant systems

Real Time Operating System (RTOS)Real time system is defined as a data processing system in which the time interval required to

process and respond to inputs is so small that it controls the environment. Real time processing isalways on line whereas on line system need not be real time. The time taken by the system to respondto an input and display of required updated information is termed as response time. So in this methodresponse time is very less as compared to the online processing.

6 Modern Operating System

Real-time systems are used as a control device in a dedicated application, when there are rigidtime requirements on the operation of a processor or the flow of data. Real-time operating system haswell-defined, fixed time constraints otherwise system will fail. For example Scientific experiments,medical imaging systems, industrial control systems, weapon systems, robots, and home-appliancecontrollers, Air traffic control system etc.

There are two types of real-time operating systems.

Hard real-time systemsIn hard real-time systems secondary storage is limited or missing with data stored in ROM.

Soft real-time systemsSoft real-time systems have limited utility than hard real-time systems. For example, Multimedia,

virtual reality, Advanced Scientific Projects like undersea exploration and planetary rovers, etc.

Distributed Operating SystemA distributed system is a collection of physically separate, possibly heterogeneous computer

systems that are networked to provide the users with access to the various resourcesDistributed system is referred to as loosely coupled system as each processor has its own local

memory; processors communicate with one another through various communications lines, such ashigh-speed buses or telephone lines. Processors in a distributed system may vary in size and function.These processors are referred as sites, nodes, and computers.

Distributed systems depend on networking for their functionality. Networks vary by the protocolsused, the distances between nodes, and the transport media. A local-area network (LAN) connectscomputers within a room, a floor, or a building. A wide-area network (WAN) usually links buildings,cities, or countries. A global company may have a WAN to connect its offices worldwide. Ametropolitan-area network (MAN) could link buildings within a city.

Types of Distributed System(a) Client Server System(b) Peer to Peer System

Client Server SystemClient-server architecture is a network architecture in which each computer is a client or a server.

Servers are powerful computers or processes dedicated to managing disk drives, printers, or networktraffic. Clients are systems on which users run applications. Clients rely on servers for resources, suchas files, devices, and even processing power. General structure of a client-server system is shown inthe figure 1.4

Server systems can be broadly categorized as compute server and file server:The compute-server system provides an interface to which a client can send a request to

perform an action (for example, read data); in response, the server executes the action and sends backresults to the client.

The file-server system provides a file-system interface where clients can create, update, read, anddelete files.

7Introduction to Operating System

Client

ServerClient

Client

Client

Fig. 1.4: General Structure of a Client-server System

Peer to Peer SystemThe peer-to-peer (P2P) systems are clients and server systems in which all nodes within the

system are considered peers, and each may act as either a client or a server, depending on whether it isrequesting or providing a service

Advantages of distributed systems Access to a shared resource increases computation speed, functionality, data availability,

and reliability. Speedup the exchange of data with one another via electronic mail. If one site fails in a distributed system, the remaining sites can potentially continue

operating. Reduction of the load on the host computer.

Disadvantages of distributed systems Implementation of the system is costly

Network Operating SystemNetwork Operating System runs on a server and provides the server with capability to manage

data, users, groups, security, applications, and other networking functions. It allows sharing file andprinter access among multiple computers in a network, typically a local area network (LAN), a privatenetwork or to other networks.

Examples of network operating systems are Microsoft Windows Server 2003, MicrosoftWindows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.

Advantages of network operating systems Centralized servers are highly stable. Security is server managed. Upgrades to new technologies and hardware can be easily integrated into the system. Remote access to servers is possible from different locations and types of systems.

8 Modern Operating System

Disadvantages of network operating systems High cost of buying and running a server. Dependency on a central location for most operations. Regular maintenance and updates are required.

Desktop SystemsA desktop system is a personal computer (PC) system in a form intended for regular use at a

single location, as opposed to a mobile laptop or portable computer. Early desktop computers weredesigned to lay flat on the desk, while modern computer systems stand upright.

Most modern desktop computer systems have separate screens and keyboards. Modern ones allsupport multiprogramming, often with dozens of programs started up at boot time. Their job is to providegood support to a single user. They are widely used for word processing, spreadsheets, and Internet access.Common examples are Linux, FreeBSD, Windows 8 and the Macintosh operating system .

Handheld SystemsA handheld computer or PDA (Personal Digital Assistant) is a small computer that fits in a shirt

pocket and performs a small number of functions, such as an electronic address book and memo pad.Since these computers can be easily fitted on the palmtop, they are also known as palmtop computers.Furthermore, many mobile phones are hardly any different from PDAs except for the keyboard and screen.

In effect, PDAs and mobile phones have essentially merged, differing mostly in size, weight, anduser interface. Almost all of them are based on 32-bit CPUs with protected mode and run asophisticated operating system.

One major difference between handhelds and PCs is that the former do not have multigigabytehard disks, which changes a lot. Two of the most popular operating systems for handhelds areSymbian OS and Android OS.

Clustered SystemsA computer cluster consists of a set of loosely connected computers that work together so that in

many respects they can be viewed as a single system. The components of a cluster are usuallyconnected to each other through fast local area networks, each node (computer used as a server)running its own instance of an operating system.

Computer clusters emerged as a number of computing trends including the availability of low costmicroprocessors, high speed networks, and software for high performance distributed computing was known.

In Clustered systems, if the monitored machine fails, the monitoring machine can take ownershipof its storage, and restart the application(s) that were running on the failed machine. The failedmachine can remain down, but the users and clients of the application would only see a briefinterruption of the service.

Clustering can be done in different ways Asymmetric clustering: one server runs the application while other servers are on standby

mode. Symmetric clustering: all N hosts are running the application.

In asymmetric clustering, one machine is in hot standby mode while the other is running theapplications. The hot standby host (machine) does nothing but monitors the active server. If that server

9Introduction to Operating System

fails, the hot standby host becomes the active server. In symmetric mode, two or more hosts arerunning applications, and they are monitoring each other. It does require that more than oneapplication be available to run.

Other forms of clusters include parallel clusters and clustering over a WAN. Parallel clustersallow multiple hosts to access the same data on the shared storage

For example, Oracle Parallel Server is a version of Oracle’s database that has been designed torun parallel clusters. Storage-area networks (SANs) are the feature development of the clusteredsystems includes the multiple hosts to multiple storage units.

Modern Operating Systems(i) Embedded Operating Systems: Embedded systems run on the computers that control

devices that are not generally thought of as computers and which do not accept user-installed software. Typical examples are microwave ovens, TV sets, cars, DVD recorders,traditional phones, and MP3 players. The main property which distinguishes embeddedsystems from handhelds is the certainty that no untrusted software will ever run on it.

(ii) Sensor-Node Operating Systems: Networks of tiny sensor nodes are being deployed fornumerous purposes. These nodes are tiny computers that communicate with each other andwith a base station using wireless communication. Sensor networks are used to protect theperimeters of buildings, guard national borders, detect fires in forests, measure temperatureand precipitation for weather forecastingThe sensors are small battery-powered computers with built-in radios. They have limited powerand must work for long periods of time. Each sensor node is a real computer, with a CPU, RAM,ROM, and one or more environmental sensors. It runs a small, but real operating system, usuallyone that is event driven, responding to external events or making measurements periodically basedon an internal clock. The operating system has to be small and simple.

(iii) Smart Card Operating Systems: The smallest operating systems run on smart cards,which are credit-card-sized devices containing a CPU chip. They have very severeprocessing power and memory constraints. Some are powered by contacts in the reader intowhich they are inserted which can handle only a single function, such as electronicpayments, but others can handle multiple functions

PRACTICE QUESTIONS

1. What is an Operating system? What are the various OS Components?2. What is the advantage of Multiprogramming?3. What are multiprocessor systems and give their advantages?4. State the various classes of an operating system.5. What are the differences between symmetric and asymmetric multiprocessing system?6. Briefly Explain Real-Time Systems.7. Write a note on Clustered Systems.8. What are the key features of classes of operating systems?9. Explain briefly about Network Operating System?

Recommended