Operating System

16
3.1. INTRODUCTION An application program cannot access input/output devices or execute program instructions itself. The operating system acts as a platform on which various application programs are executed. The user requests the application program to perform a particular task and the application program refers the request of user to operating system. An operating system is a system software that is responsible for the management of various activities of the computer and sharing of computer resources. Operating system is a collection of programs which makes interface between hardware, software and user. LEARNING OBJECTIVES At the end of this chapter you will be able to understand : Definition of Operating System Functions of Operating System Types of Operating System File System Scheduling Process Concepts Memory Management L L

description

An operating system is a system software that is responsible for the management of various activities of the computer and sharing of computer resources. Operating system is a collection of programs which makes interface between hardware, software and user.

Transcript of Operating System

Page 1: Operating System

3.1. INTRODUCTION

An application program cannot access input/output devices or execute programinstructions itself. The operating system acts as a platform on which various applicationprograms are executed. The user requests the application program to perform a particulartask and the application program refers the request of user to operating system.

An operating system is a system software that is responsible for themanagement of various activities of the computer and sharing ofcomputer resources.

Operating system is a collection of programs which makes interfacebetween hardware, software and user.

LEARNING OBJECTIVES

At the end of this chapter you will be able to understand :

� Definition of Operating System

� Functions of Operating System

� Types of Operating System

� File System

� Scheduling

� Process Concepts

� Memory Management

L

L

Page 2: Operating System

3-2 OPERATING SYSTEM

It hosts the several applications that run on a computer and handles the operations ofcomputer hardware. The operating system is responsible for managing hardwareresources. Fig. 3.1 below shows the actual position of an operating system in a computersystem.

Fig. 3.1 User Interface with the Operating System.

OS isolates user from complex internal operations. It acts as a middle-ware applicationinterface between user and hardware.

3.2. FUNCTIONS OF OPERATING SYSTEM

Operating system manages most of the operations of the computer and performs basicfunction such as:

1. User interface. Operating system provides the facilities of the user interface. Theuser interface includes the windows, menus and method of interaction between whenand the computer. Apart of the graphical user interfaces (GUIs), all operations are ofthe computer performed by in stead of commands.

2. Running programs. Operating system provides the facilities to run any program.The program which sends the request to the operating system and giving the resultsback to the program.

3. Managing files. The data and programs are stored permanently on the disk forfuture use. Application software such as word-processing, spreadsheet, databasemanagement system etc. may have hundreds of files. The operating system maintainsand manages these files.

4. Memory management. Computer memory plays very important role for dataprocessing. The data and programs are loaded from disk into in by RAM. The operatingsystem and allocates the memory areas and manages these properly.

5. I/O system management. Operating system take care of input and output devicesto be used in an efficient way.

Page 3: Operating System

OPERATING SYSTEM 3-3

6. Scheduling jobs. The operating system determines the order in which the jobs are tobe processed. Sometimes, the operating system processes jobs on a first come firstserve basis. But in some situations, one user may have higher priority than the otherusers. In this case, the operating system has to adjust the scheduling of the jobs.

7. Task management. Operating system works as a task manager. A computer canperform many tasks at a time. For example, in word processing it accepts input data,stores data on the disk and prints out a document simultaneously. Some operating systemscan handle more than one program at the same time.

8. Controlling network. Some Operating systems are specially developed, fornetworking, called the network operating systems or NOSs. A network operating systemorganizes and co-ordinates multiple users and makes it possible to access and shareresources on network.

9. Security. Operating systems provide password protection to keep unauthorized usersout of the system. They also provide backup and recovery function when a systemfailure.

3.3. TYPE OF OPERATING SYSTEM

Operating systems create a link between users and the applications from the core ofcomputer systems. It separates the programs and the hardware and simplifies resourcemanagement. Let us look at the different types of operating systems.

1. Batch processing operating systems. In batch processing operating system, theprogram, data and system commands submitted in the form of a batch. Batch operatingsystem usually allows a little or no interaction between user and an executing program.It has a greater ability for resource utilization than simple several processing. Programsthat do not require interaction and programs with long execution time may be served bya batch operating system. E.g. of such programs include payroll, forecasting, statisticalanalysis etc.

Advantages

(a) The processing time on machine is increased.

(b) CPU utilization is improved.

Disadvantages

(a) Non-interactive environment.

(b) Greater turn around time as there was much delay between jobs because ofnon-interactive environment.

(c) CPU idle time is larger.

(d) Uni program.

2. Multi-user and single-user operating systems. Multi user operating systemallows two or more users to run programs at the same time. Some operating systems

Page 4: Operating System

3-4 OPERATING SYSTEM

permit hundreds or even thousands of concurrent users. For example, In Linux it ispossible for two users to login at a time and this capability of the OS makes it a multi-user operating system. A server would be another example of a multi-user operatingsystem that allows multiple simultaneous connections.

A single user operating system only allows one user on the system. DOS is the bestexample of single user operating system.

3. Multi-tasking and single-tasking operating systems. When a single program isallowed to run at a time is called single-tasking operating system. The Palm OS for Palmhandheld computers and DOS are the examples of single-task operating system.

When operating system allows the execution of multiple tasks at one time is called multi-tasking operating system. Examples of multi tasking operating system are Windows XP,Linux, UNIX, window 7.etc.

Advantages

(a) Increased throughput.

(b) Lowered response time.

(c) Increased CPU utilization.

(d) User interaction is allows between execution of program.

Disadvantages

(a) Ideally degree of multiprogramming should results in higher resource utilization,but in some cases high degree of multiprogramming may increase waiting timefor processes and result in performance degradation starvation possible.

(b) Deadlock can occur.

4. Real-time operating systems. It is a multitasking operating system that aimsexecuting real-time applications. The main object of real-time operating systems is theirquick and predictable response to events. They either have an event-driven or a time-sharing design. An event-driven system switches between tasks based of their prioritieswhile time-sharing operating systems which tasks based on clock interrupts. Example ofreal- time operating system is MTOS, Lynx, and RTX etc.

Advantages

(a) Users are provided an interactive environment at a reasonable cost.

(b) Degree of multiprogramming and resource utilization is increased.

(c) Short response time.

5. Distributed operating systems. An operating system that manages a group ofindependent computers and makes them appear to be a single computer is known as adistributed operating system. Linux and UNIX are the examples of distributed OS.

Page 5: Operating System

OPERATING SYSTEM 3-5

6. Embedded systems. The operating system designed for being used in embeddedcomputer systems are known as embedded operating systems. They are designed tooperate on small electronics device like PDAs. Windows CE, FreeBSD and Minix 3 aresome examples of embedded operating systems.

3.4. FILE MANAGEMENT

A collection of data or information is called file. It has a name called the filename. Theinformation stored in a computer must be in a file. There are many different types offiles: data files, text files, program files, directory files, and so on. Different types of filesstore different types of information. For example, program files store programs, whereastext files store text.

The task of managing and organizing file is called file managements.

The task of file management is generally done by the operating system. Operating systemperform following memory management task:

1. Creating new files.

2. Locating the files in computer memory.

3. Sharing files between different users.

4. Organizes the files in different directories.

The Fig. 3.2 shows the hierarchy of file store in an system.

Fig. 3.2 Hierarchy of file store

The system that an operating system or program uses to organize and keep track offiles. For example, a hierarchical file system is one that uses directories to organize filesinto a tree structure.

L

Page 6: Operating System

3-6 OPERATING SYSTEM

3.4.1. What is a file system ?

Everything you install, save, edit or create on your computer comprises the trillions ofbits of data. A file system stores, organizes and allows to access files on a daily basis forcomputer users. Hard drives, CD-ROMs, DVD-ROMs and servers are all types of filesystems that allow you access to data.

File system is the structures in computer used to stores and organizesdata.

All file systems store information into some sort of directory for easy access. Somesystems create very detailed structures where others keep files in organized disarray. Itdepends on the type of file system software you are running, navigating the nodes ofinformation can be easy or difficult for the average computer user. The average computeruser relies on their operating system to take care of the file system for them, and in mostcases, this is all that is necessary for the computer user. More advanced user may findthe organization of their data to benefit from a different type of file system all together.

Most file systems can create, move and delete files and directories similar to how youwould delete a whole folder in Windows XP or Windows 98. You can simply drag anddrop the folder from one place to another. In MS-DOS, you use a sequence of commandsto eliminate a folder from the system. Other UNIX-based file system structures allowyou further abilities to modify data without diving into the advanced realm of computing.You can also limit who has access to what functions, such as creating or editing files, viafile system software within the confines of your operating system.

3.4.2. Types of file system

File systems can be classified into three different types: Disk, network and special purpose.

1. Disk files systems. These are designed to store information on a hard drive disk.FAT, NTFS and UDF are all types of disk file systems.

2. Network files systems. These file systems act as a client for file access protocolson a server. FTP, WebDAV and NFS are types of network file systems.

3. Special purpose file. These systems are the miscellaneous systems that do not fitinto the disk or network file system categories. Special purpose systems are generallyused in Unix-based systems. Flat file systems are one of the most general ways to storedata. Information is stored on the same level instead of creating sub-levels of data.

There are sub-categories of file systems as well. Database file systems, for example,identify files by their type, author or other meta data. Transactional file systems accessof files by individuals in the hopes of executing all changes at the same time banks andfinancial institutions employ this type of file structure in their computer systems to ensurethe seamless transfer of money between two accounts and other functions that requireautonomy.

L

Page 7: Operating System

OPERATING SYSTEM 3-7

3.4.3. File Attributes

Each file is stored in a directory, and uses a directory entry that describes itscharacteristics such as its name and size. The directory entry also contains a pointer towhere the file is stored on disk. One of the characteristics stored for each file is a set offile attributes that give the operating system and application software more informationabout the file and how it is intended to be used.

A file can have more than one attribute attached to it, although only certain combinationsreally make any sense.

1. Read-Only. Most software, when seeing a file marked read-only, will refuse todelete or modify it. This is pretty straight-forward. For example, DOS will say “Accessdenied” if you try to delete a read-only file.

2. Hidden. This one is pretty self-explanatory as well if the file is marked hidden thenunder normal circumstances it is hidden from view. DOS will not display the file whenyou type “DIR” unless a special flag is used.

3. System. This flag is used to tag important files that are used by the system and shouldnot be altered or removed from the disk. In essence, this is like a “more serious” read-only flag and is for the most part treated in this manner.

4. Volume label. Every disk volume can be assigned an identifying label, either when itis formatted, or later through various tools such as the DOS command “LABEL”. Thevolume label is stored in the root directory as a file entry with the label attribute set.

5. Directory. This is the bit that differentiates between entries that describe files andthose that describe subdirectories within the current directory. In theory you can converta file to a directory by changing this bit. Of course in practice, trying to do this wouldresult in a mess—the entry for a directory has to be in a specific format.

6. Archive. This is a special bit that is used as a “communications link” betweensoftware applications that modify files, and those that are used for backup.

3.4.4. File operationThe File Operation used to perform different types of operations on files and directoriessuch as create, move, delete, and also to set the attributes for files and folders. Thedifferent types of operations which can be performed by the file operation are as following:

1. Copy file. This operation is used to copy a file from one location to anotherlocation. You will need to configure both the source and destination when usingthis operation of the file.

2. Move file. This operation moves a file from one location to another.

3. Rename file. This can be used to rename a file available within a specifiedlocation.

4. Create directory. This can be used to create a folder. You will need to specifythe source location where the folder needs to be created.

Page 8: Operating System

3-8 OPERATING SYSTEM

5. Delete file. This can be used to delete a user specified file from the specifiedfolder.

6. Merge files. This operation is used to append one file to another.

7. Set attributes. This operation is used to set attributes to files and folders. Differenttypes of attributes which can be set are hidden, archive, read only and system.

8. Trunked. Earse text and write other text.

3.5. PROCESS

A process is more than the program code. It also includes the current activity, as representedby the value of the program counter and also includes the process stack containingtemporary data, and data section containing global variables.

A process can simply be defined as a program in execution it can be definedas a program currently making use of the processor at any one time.

A running program is called process.

3.5.1. Process stateAs a process executes, it changes state. The state of a process is defined in part by thecurrent activity of that process. A process can be on any of the following states as shownin Fig. 3.3.

Fig. 3.3. Process State.

L

L

Page 9: Operating System

OPERATING SYSTEM 3-9

(a) Ready. This is when the process is ready to be run on the processor.

(b) Running. This is when the process is currently making use of the processor.

(c) Blocked. This is when the process is waiting for an input such as user response ordata from another process. A process may be in the blocked state if it needs to access aresource.

(d) Suspend. This is when a process is swapped out of a memory by memory managementsystem in order to free memory for other process.

(e) Waiting. This is when a process is swapped out of memory after incurring an O/Iwait.

(f) Terminate. This is when a process has finished its run.

3.5.2. Process Control BlockWhen a process is created the operating system creates a corresponding process controlblock and when the process is terminated its process control block is released.

The operating system groups all information that it needs about aparticular process into a data structure called a process control block.

A process control block contained many pieces of information associated with specifiedprocess as shown in the Fig. 3.4.

Fig. 3.4. Process Control Block.

L

Page 10: Operating System

3-10 OPERATING SYSTEM

(a) Process state. The state may be new, ready, running, and waiting, halted and so on.

(b) CPU registers. Registers include accumulators, index registers, stack, pointer, andgeneral-purpose registers plus any condition-code information.

(c) Memory-management information. It includes such information such as value ofthe base and limit registers, the page tables, or segment tables depending on the memorysystem used by the operating system.

(d) Program counter. It indicates that address of next instruction to be executed forthis process.

(e) Accounting information. It includes the CPU time and real time used, time limit,account numbers, job or process numbers and so on.

(f) I/O status information. It includes the list of I/O devices allocated to this to process.

(g) CPU scheduling information. It includes a priority of a process, pointers toscheduling queues and any other scheduling information.

3.5.3. Process scheduling—Good job mixtureScheduling is a fundamental operating system function. The objective of multiprogrammingis to have some process running all the times, to maximize CPU utilization. The objectiveof time sharing system is to switch the CPU among processes so frequently that userscan interact with each program while it is running.

Scheduling Queues. As processes enter the system, they are put into a job queue.This queue consists of all processes in the system. The processes that are residing inmain memory and are ready and waiting to execute are kept on a list called the readyqueue. A ready-queue header will contain pointers to the first and last PCBs in the list.The list of processes waiting for a particular I/O device is called a device queue. Eachdevice has its own device queue.

3.5.4. Schedulers job mixtureA scheduler is a program of an OS that selects the next job to be admitted for execution.The main objective of scheduling is to increase CPU utilization and higher throughput.Schedulers can be divided into three types :

1. Long term scheduler.2. Medium term scheduler.3. Short term scheduler.

1. Long term scheduler. Some times it is called job scheduler. This determines whichjob shall be admitted for immediate processing. The long-term scheduler select processesfrom job pool and loads them into main memory.2. Medium term scheduler. Medium term useful when most of the processes requiresome I/O operations in that case it may become suspended for I/O operations. It isbeneficial to remove this process from main memory to hard disk to make room for other

Page 11: Operating System

OPERATING SYSTEM 3-11

processes. At some later time these processes can be reloaded into memory continuefrom where it was left earlier.

3. Short term scheduler. Short-term scheduler (CPU scheduler) selects processesfrom among the processes that are ready to execute, and allocates the CPU to one ofthem. Its main objective is to maximize system performance.

3.5.5. Scheduling algorithmThe scheduling algorithm may be:

1. First Come First Served (FCFS). This is the simplest scheduling algorithm. Withthis scheme, the process that requests the CPU first is allocated the CPU first. When ajob is submitted in FCFS scheduling it enters the ready queue. The oldest job in the readyqueue is always selected to dispatch. A FCFS results in poor performance. As aconsequence of non-preemptive there is a low rate of component utilization and systemthroughput.

2. Shortest Job First Scheduling Algorithm (SJFS). It associates with each processthe length of the next CPU burst time. When CPU is available it is assigned to theprocess that has the next smallest CPU burst time. If two processes have the samelength then FCFS is used to break the tie.

3. Round Robin Scheduling (RRS). In round robin scheduling basically CPU time isdivided into time slice. RRS utilizes the system resources in an equitable manner smallprocesses may be executed in a single time slice giving good response time whereaslong process may require several time slices. It is also one of the best-known schedulingdisciplines for achieving good distributed response time.

3.5.6. Process synchronizationIn a multiple processor system many processes can run in parallel since separateprocessors could be allocated for them.

Processes must be able to inform one another that may have completed a certain action.This is necessary to satisfy the requirements for communication system normally. Thatinformation must not be over written before the old information has been used and noattempt should be made to remove information before it has been made available for i.e.in process synchronization the terminal manager might test the variable character countagainst some suitable limit using some sequence.

3.6. MEMORY MANAGEMENT

Processes need physical memory in order to execute. The operating system managesand allocates memory to processes from physical and virtual memory. Physical memorymanagement enables the operating system to safely share physical memory amongprocesses. This allows us to multiprogramming the processor, to time-share the systemand to prevent one process from using another memory.

Page 12: Operating System

3-12 OPERATING SYSTEM

Memory management is concerned with allocation of physical memory offinite capacity to requesting process.

Memory management techniques must meet the following requirements:

(a) Processes may require more memory than available physical memory.

(b) You may need to load processes to different locations each time they execute.

(c) You may need to swap all or part of a process to secondary storage duringexecution (and then reload it at a different memory location, as above).

(d) Memory protection between processes is required.

3.6.1. Memory Management Scheme1. Swapping. It is the simplest memory management scheme. In system where partitionsare not used and all the available memory is allocated to one user.

Swapping is the process of transferring programs from the main memoryto the disk storage and back from disk to main memory.

Program swapping can be used one specific program is loaded into memory executesfor a particular amount of time and then it is swapped out to the disk storage thenanother program is allocated in the available memory.

In timesharing system when a time quantum of a process expires it is swapped out frommain memory and another process is swapped in from the disk into the main memoryspace that has been freed from the first program.

In priority based scheduling a lower priority job is rolled back on the arrival of a higherpriority job. In this case lower priority job is swapped out and higher priority job isswapped into the memory. These swapping process sometimes know as rollin as rollout.

2. Paging. Paging is a scheme of memory management which provides a solution to theproblem of external fragmentation. It does not resolve the problem of internalfragmentation completely but internal fragmentation can be reduced by choosing anappropriate page size in the scheme.

Paging is a memory management technique in which a process is splitinto a number of fixed equal size partitions and allocated non contiguousmemory spaces.

In this scheme, physical memory is broken into fixed size blocks called frames. Logicalmemory is also divided into pages, where each page is of some fixed sized as frame.When a process is to be executed its pages are loaded into available frames at not-contiguous location.

L

L

L

Page 13: Operating System

OPERATING SYSTEM 3-13

To implement paging, we need to keep track of all free frames. To run a program of sizen pages, we need to find n free frames and load the program into them. There is aproblem with internal fragmentation if a process size is not an exact number of frames.Only part of one frame is lost to this fragmentation, however, and if we make the framesize quite small, this isn't a significant problem.

With paging, the logical address generated by the CPU is divided into a page number pand a page offset d. The page number is used as an index into a page table whichcontains the base address of each page in physical memory and the page offset iscombined with the base address to define the physical memory address that is sent tothe memory unit as shown in Fig. 3.5.

Fig. 3.5 Page Table.

A page table is maintained which contains the base address of each page in physicalmemory. CPU generated address is divided in 2 parts :

(A) Page number.

(B) Page offset.

This is known as logical address. Right hand bit of logical address give the offset numberand left hand bits provide the page number. This page number works as index in thepage table and corresponding base address of that page is determinate. This base addressis combined with the page offset to obtain physical memory address.

3. Segmentation. Segmentation is a memory management technique when the usersview is map onto physical memory in this scheme.

A segment is a logical unit, such as: the main program, procedures,functions, methods, objects, local variables, global variables, commonblocks, the stack, the symbol table and arrays.

L

Page 14: Operating System

3-14 OPERATING SYSTEM

Program is divided into different logical segments each segment is allocated non-contiguousspace in memory. These segments may be of variable name. Every segment has a nameand length. User views a main program as a collection of different components such as aset subroutines, processor function etc. Segmentation support two users view of memory.

In segmentation, you have a logical address consisting of a segment number and an offsetand a segment table that maps two-dimensional physical addresses as shown in the Fig.3.6. Each table entry has a base that contains the starting physical address where segmentsreside in memory and the limit that specifies the length of the segment.

Fig. 3.6. Segmentation Table.

With each entry in the segment table, a validation bit (one that indicates whether or not itwas an illegal statement) and read/write/execute privileges are associated with the entry.Since segments can vary in length, memory allocation is a dynamic storage-allocationproblem, which can lead to external fragmentation.

POINTS TO REMEMBER(i) Operatint system acts as an mediator between user and hardware.

(ii) Operating system provides platefom to other application softwares.(iii) Operating system provides the facilities to run any program.(iv) Operating system take care of input and output devices.(v) Operating systems provide password protection to keep.

(vi) Multi user operating system allows two or more users to run programs at thesame time.

(vii) A single user operating system only allows one user on the system.

Page 15: Operating System

OPERATING SYSTEM 3-15

(viii) The task of managing and organizing file is called file managements.(ix) A running program is called process.(x) Memory management is concerned with allocation of physical memory of finite

capacity to requesting process.

KEY TERMS❍ Operating system ❍ Hardware, software, user❍ Batch processing ❍ Multi tasking and single tasking❍ File management ❍ Disk files, network file, special file❍ File attributes ❍ Read only, hidden, system, volume❍ File operation ❍ Cut, copy, move, create, delete file❍ Process state ❍ Ready, running, blocked, suspend, waiting

MULTIPLE CHOICE QUESTIONS1. An operating system is a software component of a computer system that is

(a) Responsible for the management of various activities of the computer(b) The sharing of computer resources(c) Both (a) and (b)(d) None of above

2. Operating system manages all the operations of the computer and performsbasic tasks(a) Accepts input from input devices(b) Sends output to output devices(c) Manages the application programs in memory(d) Manages the files on the storage devices(e) All of above

3. A distributed system is a(a) Collection of processors (b) Collection of data(c) Collection of information (d) None of above

4. The main major activities of an operating system in regard to file managementare(a) The creation and deletion of files(b) The creation and deletion of directions(c) The mapping of files onto secondary storage(d) (a) and (b)(e) All of above

5. The examples of personal computer operating system are:(a) DOS (b) Mac OS(c) Windows (d) All of above(e) (a) and (c)

Page 16: Operating System

3-16 OPERATING SYSTEM

6. In multiprocessing, multiple programs are executed on(a) Different processors at same time(b) Multiple site(c) Multiple editor (d) None of above

7. Spooling is a technique in which an operating system uses(a) Buffers to place data before transferring it(b) Input and output device for connection(c) More then one user (d) Multitasking concept

8. Compiler is a computer program that(a) Convert high level language to machine language(b) Machine to assembly(c) Assembly to high level language(d) All of above

9. Loader is the part of an operating system that is responsible for(a) Linking the content of program(b) Loading programs, that is, starting up programs by reading the contents of

executable(c) Executing the program contents(d) All of above

10. The Assembly language consists instruction statements which are used to definethe program operations(a) Op-code mnemonics (b) Data sections(c) Assembly directives (d) All of above(e) (a) and (c)

ANSWERS1. (c) 2. (e) 3. (a) 4. (e) 5. (d)6. (a) 7. (a) 8. (a) 9. (b) 10. (d)

UNSOLVED QUESTIONS1. What is operating system ? Explain the function of operating system.

2. Draw the block diagram of operating system.

3. Explain different types of operating system.

4. What is file system ? Explain difference file system.

5. What is process ? Explain the state of a process.

6. Explain PCB with the help of diagram.

7. What do you mean by memory management ?

8. Explain the difference between paging and segmentation.❍ ❍ ❍