Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Operating Systems Lecture Notes for B.Tech II Year-II Sem (R20) at Malla Reddy College of Engineering & Technology, Lecture notes of Operating Systems

Lecture notes for the Operating Systems course offered to second-year B.Tech students in the Computer Science & Engineering department at Malla Reddy College of Engineering & Technology. The notes cover topics such as operating system structures, Linux shell, process and CPU scheduling, deadlocks, interprocess communication mechanisms, memory management, and virtual memory. The course objectives include understanding fundamental concepts and techniques of operating systems, studying Linux shell and scheduling, and understanding concepts in deadlocks and process management.

Typology: Lecture notes

2020/2021

Uploaded on 05/11/2023

johnatan
johnatan 🇺🇸

4

(29)

280 documents

1 / 161

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
i
OPERATING SYSTEMS
(R20A0504)
LECTURE NOTES
B.TECH II YEAR II SEM (R20)
(2020-21)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY
(Autonomous Institution UGC, Govt. of India)
(Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC ‘A’ Grade - ISO 9001:2015 Certified)
Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad 500100, Telangana State, INDIA.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Operating Systems Lecture Notes for B.Tech II Year-II Sem (R20) at Malla Reddy College of Engineering & Technology and more Lecture notes Operating Systems in PDF only on Docsity!

i

OPERATING SYSTEMS

(R20A0504)

LECTURE NOTES

B.TECH II YEAR – II SEM (R20)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY

(Autonomous Institution – UGC, Govt. of India) (Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO 9001:2015 Certified) Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100, Telangana State, INDIA.

ii

MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

II Year B.Tech. CSE- I Sem L/T/P/C 3/-/-/ (R20A0504) OPERATING SYSTEM Course Objectives:

  1. To understand the fundamental concepts and techniques of Operating Systems.
  2. To study the concepts of linux shell and scheduling.
  3. To understand the concepts in deadlocks and process management.
  4. To understand the concepts in memory managements and IPC mechanism.
  5. To study the concept of file system concepts and sockets. UNIT – I Operating System - Introduction, Structures-Simple Batch, Multi-programmed, Time-shared, Personal Computer, Parallel, Distributed Systems, Real-Time Systems , System components, Operating System services. Introduction to Linux operating system, linux file system, Linux Utilities UNIT – II Linux: Introduction to shell, Types of shell's , example shell programs. Process and CPU Scheduling - Process concepts and scheduling, Operations on processes, Cooperating Processes, Threads, Scheduling Criteria, Scheduling Algorithms, Multiple - Processor Scheduling. UNIT – III Deadlocks - System Model, Deadlocks Characterization, Methods for Handling Deadlocks, Deadlock Prevention, Deadlock Avoidance, Deadlock Detection, and Recovery from Deadlock Process Management and Synchronization - The Critical Section Problem, Synchronization Hardware, Semaphores, and Classical Problems of Synchronization, Critical Regions, Monitors UNIT – IV Interprocess Communication Mechanisms : IPC between processes on a single computer system, IPC between processes on different systems, using pipes, FIFOs, message queues, shared memory implementation in linux. Corresponding system calls. Memory Management and Virtual Memory - Logical versus Physical Address Space, Swapping, Contiguous Allocation, Paging, Segmentation, Segmentation with Paging, Demand Paging, Page Replacement, Page Replacement Algorithms. UNIT - V

iv

OPERATING SYSTEMS NOTES II YEAR/I SEM MRCET

INDEX

UNIT NO TOPIC PAGE NO

I

Introduction Operating System concepts (^1) - 2 Types of Operating Systems, Operating System Components

Operating services (^9) - 13 Introduction to Linux (^13) - 23 II Process & CPU Scheduling Shell Programming 24 - 40 Process concepts and scheduling 40 - 43 Operations on Process, Cooperating Processes (^40) - 43 Threads, Scheduling Criteria 43 - 46 Scheduling Algorithms, Multiprocessor scheduling

III

Deadlocks & Process Management System Model, Deadlocks Characterization (^55) - 56 Methods for Handling Deadlocks (^56) - 63 The Critical Section Problem (^63) - 69 Classical Problems of Synchronization (^69) - 78 IV (^) Interprocess Communication IPC between processes on a single computer system

shared memory implementation in linux (^83) - 89 Paging & Segmentation (^89) - 122 V (^) File System Interface and Operations Access methods (^123) - 126 Directory Structure. File System Structure (^126) - 139 Allocation methods, Disk Scheduling Algorithms

 The Application programs like spreadsheets, Web browsers, word processors, etc. are used to define the ways in which these resources are used to solve the computing problems of the users. And the System program mainly consists of compilers, loaders, editors, OS, etc.  The Operating System is mainly used to control the hardware and coordinate its use among the various application programs for the different users.  Basically, Computer System mainly consists of hardware, software, and data. OS is mainly designed in order to serve two basic purposes:

  1. The operating system mainly controls the allocation and use of the computing System’s resources among the various user and tasks.
  2. It mainly provides an interface between the computer hardware and the programmer that simplifies and makes feasible for coding, creation of application programs and debugging Two Views of Operating System
  3. User's View
  4. System View Operating System: User View The user view of the computer refers to the interface being used. Such systems are designed for one user to monopolize its resources, to maximize the work that the user is performing. In these cases, the operating system is designed mostly for ease of use, with some attention paid to performance, and none paid to resource utilization. Operating System: System View The operating system can be viewed as a resource allocator also. A computer system consists of many resources like - hardware and software - that must be managed efficiently. The operating system acts as the manager of the resources, decides between conflicting requests, controls the execution of programs, etc. Types of Operating System Given below are different types of Operating System:
  5. Simple Batch System
  6. Multiprogrammed
  7. Time-Shared
  8. Personal Computer
  9. Parallel
  10. Distributed Systems
  11. Real Time Systems

1. Simple Batch System In a Batch Operating System, the similar jobs are grouped together into batches with the help of some operator and these batches are executed one by one. For example, let us assume that we have 10 programs that need to be executed. Some programs are written in C++, some in C and rest in Java. Now, every time when we run these programmes individually then we will have to load the compiler of that particular language and then execute the code. But what if we make a batch of these 10 programmes. The benefit with this approach is that, for the C++ batch, you need to load the compiler only once. Similarly, for Java and C, the compiler needs to be loaded only once and the whole batch gets executed. The following image describes the working of a Batch Operating System. Advantages:

  1. The overall time taken by the system to execute all the programmes will be reduced.
  2. The Batch Operating System can be shared between multiple users. Disadvantages:
  3. Manual interventions are required between two batches.
  4. The CPU utilization is low because the time taken in loading and unloading of batches is very high as compared to execution time. Multiprogramming Sharing the processor, when two or more programs reside in memory at the same time, is referred as multiprogramming. Multiprogramming assumes a single shared processor. Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has one to execute.

Advantages:

  1. Since equal time quantum is given to each process, so each process gets equal opportunity to execute.
  2. The CPU will be busy in most of the cases and this is good to have case. Disadvantages:
  3. Process having higher priority will not get the chance to be executed first because the equal opportunity is given to each process. Personal Computers Personal computer operating system provides a good interface to a single user. Personal computer operating systems are widely used for word processing, spreadsheets and Internet access. Personal computer operating system are made only for personal.You can say that your laptops, computer systems, tablets etc. are your personal computers and the operating system such as windows 7, windows 10, android, etc. are your personal computer operating system. And you can use your personal computer operating system for your personal purposes, for example, to chatting with your friends using some social media sites, reading some articles from internet, making some projects through microsoft powerpoint or any other, designing your website, programming something, watching some videos and movies, listening to some songs and many more. Parallel Processing

Parallel processing requires multiple processors and all the processor works simultaneously in the system. Here, the task is divided into subparts and these subparts are then distributed among the available processors in the system. Parallel processing completes the job on the shortest possible time. All the processors in the parallel processing environment should run on the same operating system. All processors here are tightly coupled and are packed in one casing. All the processors in the system share the common secondary storage like the hard disk. As this is the first place where the programs are to be placed. There is one more thing that all the processors in the system share i.e. the user terminal (from where the user interact with the system). The user need not to be aware of the inner architecture of the machine. He should feel that he is dealing with the single processor only and his interaction with the system would be the same as in a single processor, Advantages

  1. It saves time and money as many resources working together will reduce the time and cut potential costs.
  2. It can be impractical to solve larger problems on Serial Computing.
  3. It can take advantage of non-local resources when the local resources are finite.
  4. Serial Computing ‘wastes’ the potential computing power, thus Parallel Computing makes better work of the hardware. Disadvantages
  5. It addresses such as communication and synchronization between multiple sub-tasks and processes which is difficult to achieve.
  6. The algorithms must be managed in such a way that they can be handled in a parallel mechanism.

Real-Time Operating System: It is developed for real-time applications where data should be processed in a fixed, small duration of time. It is used in an environment where multiple processes are supposed to be accepted and processed in a short time. RTOS requires quick input and immediate response, e.g., in a petroleum refinery, if the temperate gets too high and crosses the threshold value, there should be an immediate response to this situation to avoid the explosion. Similarly, this system is used to control scientific instruments, missile launch systems, traffic lights control systems, air traffic control systems, etc. This system is further divided into two types based on the time constraints: Hard Real-Time Systems: These are used for the applications where timing is critical or response time is a major factor; even a delay of a fraction of the second can result in a disaster. For example, airbags and automatic parachutes that open instantly in case of an accident. Besides this, these systems lack virtual memory. Soft Real-Time Systems: These are used for application where timing or response time is less critical. Here, the failure to meet the deadline may result in a degraded performance instead of a disaster. For example, video surveillance (cctv), video player, virtual reality, etc. Here, the deadlines are not critical for every task every time. Advantages of real-time operating system: o The output is more and quick owing to the maximum utilization of devices and system o Task shifting is very quick, e.g., 3 microseconds, due to which it seems that several tasks are executed simultaneously o Gives more importance to the currently running applications than the queued application o It can be used in embedded systems like in transport and others. o It is free of errors.

o Memory is allocated appropriately. Disadvantages of real-time operating system: o A fewer number of tasks can run simultaneously to avoid errors. o It is not easy for a designer to write complex and difficult algorithms or proficient programs required to get the desired output. o Specific drivers and interrupt signals are required to respond to interrupts quickly. o It may be very expensive due to the involvement of the resources required to work. An operating system is an interface which provides services to both the user and to the programs. It provides an environment for the program to execute. It also provides users with the services of how to execute programs in a convenient manner. The operating system provides some services to program and also to the users of those programs. The specific services provided by the OS are off course different. Following are the common services provided by an operating system:

  1. Program execution
  2. I/O operations
  3. File system manipulation
  4. Communication
  5. Error detection
  6. Resource allocation
  7. Protection 1) Program Execution  An operating system must be able to load many kinds of activities into the memory and to run it. The program must be able to end its execution, either normally or abnormally.  A process includes the complete execution of the written program or code. There are some of the activities which are performed by the operating system:

 Both the processes can be on one computer or a different computer, but are connected through a computer network. 5) Error handling An error is one part of the system that may cause malfunctioning of the complete system. The operating system constantly monitors the system for detecting errors to avoid some situations. This give relives to the user of the worry of getting an error in the various parts of the system causing malfunctioning. The error can occur anytime and anywhere. The error may occur anywhere in the computer system like in CPU, in I/O devices or in the memory hardware. There are some activities that are performed by an operating system:  The OS continuously checks for the possible errors.  The OS takes an appropriate action to correct errors and consistent computing. 6) Resource management When there are multiple users or multiple jobs running at the same time resources must be allocated to each of them. There are some major activities that are performed by an operating system:  The OS manages all kinds of resources using schedulers.  CPU scheduling algorithm is used for better utilization of CPU. 7) Protection The owners of information stored in a multi-user computer system want to control its use. When several disjoints processes execute concurrently it should not be possible for any process to interfere with another process. Every process in the computer system must be secured and controlled. Operating system can be implemented with the help of various structures. The structure of the OS depends mainly on how the various common components of the operating system are interconnected and melded into the kernel. Depending on this we have following structures of the operating system: Simple structure: Such operating systems do not have well defined structure and are small, simple and limited systems. The interfaces and levels of functionality are not well separated. MS-DOS is an example of such operating system. In MS-DOS application programs are able to access the basic I/O routines. These types of operating system cause the entire system to crash if one of the user programs fails. Diagram of the structure of MS-DOS is shown below.

Advantages of Simple structure:  It delivers better application performance because of the few interfaces between the application program and the hardware.  Easy for kernel developers to develop such an operating system. Disadvantages of Simple structure:  The structure is very complicated as no clear boundaries exists between modules.  It does not enforce data hiding in the operating system. Layered structure: An OS can be broken into pieces and retain much more control on system. In this structure the OS is broken into number of layers (levels). The bottom layer (layer 0) is the hardware and the topmost layer (layer N) is the user interface. These layers are so designed that each layer uses the functions of the lower level layers only. This simplifies the debugging process as if lower level layers are debugged and an error occurs during debugging then the error must be on that layer only as the lower level layers have already been debugged. The main disadvantage of this structure is that at each layer, the data needs to be modified and passed on which adds overhead to the system. Moreover careful planning of the layers is necessary as a layer can use only lower level layers. UNIX is an example of this structure.

files/ user files are arranged.  Shell - Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs etc.  Security - Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data. Linux Advantages

  1. Low cost: You don‘t need to spend time and money to obtain licenses since Linux and much of its software come with the GNU General Public License. You can start to work immediately without worrying that your software may stop working anytime because the free trial version expires. Additionally, there are large repositories from which you can freely download high quality software for almost any task you can think of.
  2. Stability: Linux doesn‘t need to be rebooted periodically to maintain performance levels. It doesn‘t freeze up or slow down over time due to memory leaks and such. Continuous up- times of hundreds of days (up to a year or more) are not uncommon.
  3. Performance: Linux provides persistent high performance on workstations and on networks. It can handle unusually large numbers of users simultaneously, and can make old computers sufficiently responsive to be useful again.
  4. Network friendliness: Linux was developed by a group of programmers over the Internet and has therefore strong support for network functionality; client and server systems can be easily set up on any computer running Linux. It can perform tasks such as network backups faster and more reliably than alternative systems.
  5. Flexibility: Linux can be used for high performance server applications, desktop applications, and embedded systems. You can save disk space by only installing the components needed for a particular use. You can restrict the use of specific computers by installing for example only selected office applications instead of the whole suite.
  6. Compatibility: It runs all common UNIX software packages and can process all common file formats.
  7. Choice: The large number of Linux distributions gives you a choice. Each distribution is developed and supported by a different organization. You can pick the one you like best; the core functionalities are the same; most software runs on most distributions.
  8. Fast and easy installation: Most Linux distributions come with user-friendly installation

and setup programs. Popular Linux distributions come with tools that make installation of additional software very user friendly as well.

  1. Full use of hard disk: Linux continues work well even when the hard disk is almost full. Multi-tasking: Linux is designed to do many things at the same time; e.g., a large printing job in the background won‘t slow down your other work.
  2. Security: Linux is one of the most secure operating systems. ―Walls‖ and flexible file access permission systems prevent access by unwanted visitors or viruses. Linux users have to option to select and safely download software, free of charge, from online repositories containing thousands of high quality packages. No purchase transactions requiring credit card numbers or other sensitive personal information are necessary.
  3. Open Source: If you develop software that requires knowledge or modification of the operating system code, LINUX‘s source code is at your fingertips. Most Linux applications are Open Source as well. Layered Architecture: Linux System Architecture is consists of following layers  Hardware layer - Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).  Kernel - Core component of Operating System, interacts directly with hardware, provides low level services to upper layer components.  Shell - An interface to kernel, hiding complexity of kernel's functions from users. Takescommands from user and executes kernel's functions.  Utilities - Utility programs giving user most of the functionalities of an operating systems. LINUX File system Linux file structure files are grouped according to purpose. Ex: commands, data files, documentation. Parts of a Unix directory tree are listed below. All directories are grouped under the root entry "/". That part of the directory tree is left out of the below diagram.
  4. / – Root