Operating systems


Published on

KSOU BCA books

Published in: Education, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Operating systems

  1. 1. E-528-529, sector-7, Dwarka, New delhi-110075 (Nr. Ramphal chowk and Sector 9 metro station) Ph. 011-47350606, (M) 7838010301-04 www.eduproz.inEducate Anytime...Anywhere..."Greetings For The Day"About EduprozWe, at EduProz, started our voyage with a dream of making higher education available for everyone. Sinceits inception, EduProz has been working as a stepping-stone for the students coming from variedbackgrounds. The best part is – the classroom for distance learning or correspondence courses for bothmanagement (MBA and BBA) and Information Technology (MCA and BCA) streams are free of cost. Experienced faculty-members, a state-of-the-art infrastructure and a congenial environment for learning -are the few things that we offer to our students. Our panel of industrial experts, coming from variousindustrial domains, lead students not only to secure good marks in examination, but also to get an edge overothers in their professional lives. Our study materials are sufficient to keep students abreast of the presentnuances of the industry. In addition, we give importance to regular tests and sessions to evaluate ourstudents’ progress. Students can attend regular classes of distance learning MBA, BBA, MCA and BCA courses at EduProzwithout paying anything extra. Our centrally air-conditioned classrooms, well-maintained library and well-equipped laboratory facilities provide a comfortable environment for learning.Honing specific skills is inevitable to get success in an interview. Keeping this in mind, EduProz has a careercounselling and career development cell where we help student to prepare for interviews. Our dedicatedplacement cell has been helping students to land in their dream jobs on completion of the course.EduProz is strategically located in Dwarka, West Delhi (walking distance from Dwarka Sector 9 MetroStation and 4-minutes drive from the national highway); students can easily come to our centre fromanywhere Delhi and neighbouring Gurgaon, Haryana and avail of a quality-oriented education facility atapparently no extra cost.Why Choose Edu Proz for distance learning? • Edu Proz provides class room facilities free of cost. • In EduProz Class room teaching is conducted through experienced faculty. • Class rooms are spacious fully air-conditioned ensuring comfortable ambience. • Course free is not wearily expensive. • Placement assistance and student counseling facilities. • Edu Proz unlike several other distance learning courses strives to help and motivate pupils to get
  2. 2. high grades thus ensuring that they are well placed in life. • Students are groomed and prepared to face interview boards. • Mock tests, unit tests and examinations are held to evaluate progress. • Special care is taken in the personality development department. "HAVE A GOOD DAY" Karnataka State Open University(KSOU) was established on 1st June 1996 with the assent of H.E. Governor ofKarnatakaas a full fledged University in the academic year 1996 vide GovernmentnotificationNo/EDI/UOV/dated 12th February 1996 (Karnataka State Open UniversityAct – 1992).The act was promulgated with the object to incorporate an Open University at theState level for the introduction and promotion of Open University and DistanceEducation systems in theeducation pattern of the State and the country for the Co-ordination anddetermination of standard of such systems. Keeping in view the educationalneeds of our country, in general, and state in particular the policies andprogrammes have been geared to cater to the needy.Karnataka State Open University is a UGC recognised University of DistanceEducation Council (DEC), New Delhi, regular member of the Association ofIndian Universities (AIU), Delhi, permanent member of Association ofCommonwealth Universities (ACU), London, UK, Asian Association of OpenUniversities (AAOU), Beijing, China, and also has association withCommonwealth of Learning (COL).Karnataka State Open University is situated at the North–Western end of theManasagangotri campus, Mysore. The campus, which is about 5 kms, from thecity centre, has a serene atmosphere ideally suited for academic pursuits. TheUniversity houses at present the Administrative Office, Academic Block, LectureHalls, a well-equipped Library, Guest HouseCottages, a Moderate Canteen, Girls Hostel and a few cottages providing limitedaccommodation to students coming to Mysore for attending the ContactProgrammes or Term-end examinations.
  3. 3. Unit 1: Overview of the Operating Systems: This unit covers introduction, evolution of OS. And also covers the OS components andits services.Introduction to Operating SystemsPrograms, Code files, Processes and Threads • A sequence of instructions telling the computer what to do is called a program. The user normally uses a text editor to write their program in a high level language, such as Pascal, C, Java, etc. Alternatively, they may write it in assembly language. Assembly language is a computer language whose statements have an almost one to one correspondence to the instructions understood by the CPU of the computer. It provides a way of specifying in precise detail what machine code the assembler should create. A compiler is used to translate a high level language program into assembly language or machine code, and an assembler is used to translate an assembly language program into machine code. A linker is used to combine relocatable object files (code files corresponding to incomplete portions of a program) into executable code files (complete code files, for which the addresses have been resolved for all global functions and variables). The text for a program written in a high level language or assembly language is normally saved in a source file on disk. Machine code for a program is normally saved in a code file on disk. The machine code is loaded into the virtual memory for a process, when the process attempts to execute the program. The notion of a program is becoming more complex nowadays, because of shared libraries. In the old days, the user code for a process was all in one file. However, with GUI libraries becoming so large, this is no longer possible. Library code is now stored in memory that is shared by all processes that use it. Perhaps it is best to use the term program for the machine code stored in or derived from a single code file. Code files contain more than just machine code. On UNIX, a code file starts with a header, containing information on the position and size of the code (”text”), initialised data, and uninitialised data segments of the code file. The header also contains other information, such as the initial value to give the program counter (the “entry point”) and global pointer register. The data for the code and initialised data segments then follows.
  4. 4. As well the above information, code files can contain a symbol table – a table indicating the names of all functions and global variables, and the virtual addresses they correspond to. The symbol table is used by the linker, when it combines several relocatable object files into a single executable code file, to resolve references to functions in shared libraries. The symbol table is also used for debugging. The structure of UNIX code files on the Alpha is very complex, due to the use of shared libraries.• When a user types in the name of a command in the UNIX shell, this results in the creation of what is called a process. On any large computer, especially one with more than one person using it at the same time, there are normally many processes executing at any given time. Under UNIX, every time a user types in a command, they create a separate process. If several users execute the same command, then each one creates a different process. The Macintosh is a little different from UNIX. If the user double clicks on several data files for an application, only one process is created, and this process manages all the data files. A process is the virtual memory, and information on open files, and other operating system resources, shared by its threads of execution, all executing in the same virtual memory. The threads in a process execute not only the code from a user program. They can also execute the shared library code, operating system kernel code, and (on the Alpha) what is called PALcode. A process is created to execute a command. The code file for the command is used to initialise the virtual memory containing the user code and global variables. The user stack for the initial thread is cleared, and the parameters to the command are passed as parameters to the main function of the program. Files are opened corresponding to the standard input and output (keyboard and screen, unless file redirection is used). When a process is created, it is created with a single thread of execution. Conventional processes never have more than a single thread of execution, but multi-threaded processes are now becoming common place. We often speak about a program executing, or a process executing a program, when we really mean a thread within the process executes the program. In UNIX, a new process executing a new program is created by the fork() system call (which creates an almost identical copy of an existing process, executing the same program), followed by the exec() system call (which replaces the program being executed by the new program).
  5. 5. In the Java programming language, a new process executing a new program is created by the exec() method in the Runtime class. The Java exec() is probably implemented as a combination of the UNIX fork() and exec() system calls.• A thread is an instance of execution (the entity that executes). All the threads that make up a process share access to the same user program, virtual memory, open files, and other operating system resources. Each thread has its own program counter, general purpose registers, and user and kernel stack. The program counter and general purpose registers for a thread are stored in the CPU when the thread is executing, and saved away in memory when it is not executing. The Java programming language supports the creation of multiple threads. To create a thread in Java, we create an object that implements the Runnable interface (has a run() method), and use this to create a new Thread object. To initiate the execution of the thread, we invoke the start() method of the thread, which invokes the run() method of the Runnable object. The threads that make up a process need to use some kind of synchronisation mechanism to avoid more than one thread accessing shared data at the same time. In Java, synchronisation is done by synchronised methods. The wait(), notifyO, and notifyAU() methods in the Object class are used to allow a thread to wait until the data has been updated by another thread, and to notify other threads when the data has been altered. In UNIX C, the pthreads library contains functions to create new threads, and provide the equivalent of synchronised methods, waitO, notifyO, etc. The Java mechanism is in fact based on the pthreads library. In Java, synchronisation is built into the design of the language (the compiler knows about synchronised methods). In C, there is no syntax to specify that a function (method) is synchronised, and the programmer has to explicitly put in code at the start and end of the method to gain and relinquish exclusive access to a data structure. Some people call threads lightweight processes, and processes heavyweight processes. Some people call processes tasks. Many application programs, such as Microsoft word, are starting to make use of multiple threads. For example, there is a thread that processes the input, and a thread for doing repagination in the background. A compiler could have multiple threads, one for lexical analysis, one for parsing, one for analysing the abstract syntax tree. These can all execute in parallel, although the parser cannot execute ahead of the lexical analyser, and the abstract syntax tree analyser can only process the portion of the abstract syntax tree already generated by the parser. The code for performing graphics can easily be sped up by having multiple threads, each painting a portion of the screen. File and network servers have to deal with multiple external requests, many of which block before the reply is given. An elegant way of programming servers is to have a thread for each request.
  6. 6. Multi-threaded processes are becoming very important, because computers withmultiple processors are becoming commonplace, as are distributed systems, and servers.It is important that you learn how to program in this manner. Multi-threadedprogramming, particularly dealing with synchronisation issues, is not trivial, and a goodconceptual understanding of synchronisation is essential. Synchronisation is dealt withfully in the stage 3 operating systems paper.ObjectivesAn operating system can be thought of as having three objectives:Convenience: An operating system makes a computer more convenient to use.Efficiency: An operating system allows the computer system resources to be used in anefficient manner.Ability to evolve: An operating system should be constructed in such a way as to permitthe effective development, testing and introduction of new system functions withoutinterfering with current services provided.What is an Operating System?An operating system (OS) is a program that controls the execution of an applicationprogram and acts as an interface between the user and computer hardware. The purposeof an OS is to provide an environment in which a user can execute programs in aconvenient and efficient manner.The operating system must provide certain services to programs and to the users of thoseprograms in order to make the programming task easier, these services will differ fromone OS to another.Functions of an Operating SystemModern Operating systems generally have following three major goals. Operatingsystems generally accomplish these goals by running processes in low privilege andproviding service calls that invoke the operating system kernel in high-privilege state.To hide details of hardwareAn abstraction is software that hides lower level details and provides a set of higher-levelfunctions. An operating system transforms the physical world of devices, instructions,memory, and time into virtual world that is the result of abstractions built by theoperating system. There are several reasons for abstraction.
  7. 7. First, the code needed to control peripheral devices is not standardized. Operatingsystems provide subroutines called device drivers that perform operations on behalf ofprograms for example, input/output operations.Second, the operating system introduces new functions as it abstracts the hardware. Forinstance, operating system introduces the file abstraction so that programs do not have todeal with disks.Third, the operating system transforms the computer hardware into multiple virtualcomputers, each belonging to a different program. Each program that is running is calleda process. Each process views the hardware through the lens of abstraction.Fourth, the operating system can enforce security through abstraction.Resources ManagementAn operating system as resource manager, controls how processes (the active agents)may access resources (passive entities). One can view Operating Systems from twopoints of views: Resource manager and Extended machines. Form Resource managerpoint of view Operating Systems manage the different parts of the system efficiently andfrom extended machines point of view Operating Systems provide a virtual machine tousers that is more convenient to use. The structurally Operating Systems can be design asa monolithic system, a hierarchy of layers, a virtual machine system, a micro-kernel, orusing the client-server model. The basic concepts of Operating Systems are processes,memory management, I/O management, the file systems, and security.Provide a effective user interfaceThe user interacts with the operating systems through the user interface and usuallyinterested in the look and feel of the operating system. The most important componentsof the user interface are the command interpreter, the file system, on-line help, andapplication integration. The recent trend has been toward increasingly integratedgraphical user interfaces that encompass the activities of multiple processes on networksof computers.Evolution of Operating SystemOperating system and computer architecture have had a great deal of influence on eachother. To facilitate the use of the hardware, OS’s were developed. As operating systemswere designed and used, it became obvious that changes in the design of the hardwarecould simplify them.Early SystemsIn the earliest days of electronic digital computing, everything was done on the barehardware. Very few computers existed and those that did exist were experimental in
  8. 8. nature. The researchers who were making the first computers were also the programmersand the users. They worked directly on the “bare hardware”. There was no operatingsystem. The experimenters wrote their programs in assembly language and a runningprogram had complete control of the entire computer. Debugging consisted of acombination of fixing both the software and hardware, rewriting the object code andchanging the actual computer itself.The lack of any operating system meant that only one person could use a computer at atime. Even in the research lab, there were many researchers competing for limitedcomputing time. The first solution was a reservation system, with researchers signing upfor specific time slots.The high cost of early computers meant that it was essential that the rare computers beused as efficiently as possible. The reservation system was not particularly efficient. If aresearcher finished work early, the computer sat idle until the next time slot. If theresearcher’s time ran out, the researcher might have to pack up his or her work in anincomplete state at an awkward moment to make room for the next researcher. Evenwhen things were going well, a lot of the time the computer actually sat idle while theresearcher studied the results (or studied memory of a crashed program to figure out whatwent wrong).The solution to this problem was to have programmers prepare their work off-line onsome input medium (often on punched cards, paper tape, or magnetic tape) and then handthe work to a computer operator. The computer operator would load up jobs in the orderreceived (with priority overrides based on politics and other factors). Each job still ranone at a time with complete control of the computer, but as soon as a job finished, theoperator would transfer the results to some output medium (punched tape, paper tape,magnetic tape, or printed paper) and deliver the results to the appropriate programmer. Ifthe program ran to completion, the result would be some end data. If the programcrashed, memory would be transferred to some output medium for the programmer tostudy (because some of the early business computing systems used magnetic corememory, these became known as “core dumps”)Soon after the first successes with digital computer experiments, computers moved out ofthe lab and into practical use. The first practical application of these experimental digitalcomputers was the generation of artillery tables for the British and American armies.Much of the early research in computers was paid for by the British and Americanmilitaries. Business and scientific applications followed.As computer use increased, programmers noticed that they were duplicating the sameefforts.Every programmer was writing his or her own routines for I/O, such as reading inputfrom a magnetic tape or writing output to a line printer. It made sense to write a commondevice driver for each input or output device and then have every programmer share thesame device drivers rather than each programmer writing his or her own. Some
  9. 9. programmers resisted the use of common device drivers in the belief that they could write“more efficient” or faster or “”better” device drivers of their own.Additionally each programmer was writing his or her own routines for fairly commonand repeated functionality, such as mathematics or string functions. Again, it made senseto share the work instead of everyone repeatedly “reinventing the wheel”. These sharedfunctions would be organized into libraries and could be inserted into programs asneeded. In the spirit of cooperation among early researchers, these library functions werepublished and distributed for free, an early example of the power of the open sourceapproach to software development.Simple Batch SystemsWhen punched cards were used for user jobs, processing of a job involved physicalactions by the system operator, e.g., loading a deck of cards into the card reader, pressingswitches on the computer’s console to initiate a job, etc. These actions wasted a lot ofcentral processing unit (CPU) time. Operating System User Program Area Figure 1.1: Simple Batch SystemTo speed up processing, jobs with similar needs were batched together and were run as agroup. Batch processing (BP) was implemented by locating a component of the BPsystem, called the batch monitor or supervisor, permanently in one part of computer’smemory. The remaining memory was used to process a user job – the current job in thebatch as shown in the figure 1.1 above.The delay between job submission and completion was considerable in batch processedsystem as a number of programs were put in a batch and the entire batch had to beprocessed before the results were printed. Further card reading and printing were slow asthey used slower mechanical units compared to CPU which was electronic. The speedmismatch was of the order of 1000. To alleviate this problem programs were spooled.Spool is an acronym for simultaneous peripheral operation on-line. In essence the ideawas to use a cheaper processor known as peripheral processing unit (PPU) to readprograms and data from cards store them on a disk. The faster CPU read programs/datafrom the disk processed them and wrote the results back on the disk. The cheaperprocessor then read the results from the disk and printed them.Multi Programmed Batch SystemsEven though disks are faster than card reader/ printer they are still two orders ofmagnitude slower than CPU. It is thus useful to have several programs ready to runwaiting in the main memory of CPU. When one program needs input/output (I/O) from
  10. 10. disk it is suspended and another program whose data is already in main memory (asshown in the figure 1.2 bellow) is taken up for execution. This is calledmultiprogramming. Operating System Program 1 Program 2 Program 3 Program 4 Figure 1.2: Multi Programmed Batch SystemsMultiprogramming (MP) increases CPU utilization by organizing jobs such that the CPUalways has a job to execute. Multiprogramming is the first instance where the operatingsystem must make decisions for the user.The MP arrangement ensures concurrent operation of the CPU and the I/O subsystem. Itensures that the CPU is allocated to a program only when it is not performing an I/Ooperation.Time Sharing SystemsMultiprogramming features were superimposed on BP to ensure good utilization of CPUbut from the point of view of a user the service was poor as the response time, i.e., thetime elapsed between submitting a job and getting the results was unacceptably high.Development of interactive terminals changed the scenario. Computation became an on-line activity. A user could provide inputs to a computation from a terminal and could alsoexamine the output of the computation on the same terminal. Hence, the response timeneeded to be drastically reduced. This was achieved by storing programs of several usersin memory and providing each user a slice of time on CPU to process his/her program.Distributed SystemsA recent trend in computer system is to distribute computation among several processors.In the loosely coupled systems the processors do not share memory or a clock. Instead,each processor has its own local memory. The processors communicate with one anotherusing communication network.The processors in a distributed system may vary in size and function, and referred by anumber of different names, such as sites, nodes, computers and so on depending on thecontext. The major reasons for building distributed systems are:
  11. 11. Resource sharing: If a number of different sites are connected to one another, then auser at one site may be able to use the resources available at the other.Computation speed up: If a particular computation can be partitioned into a number ofsub computations that can run concurrently, then a distributed system may allow a user todistribute computation among the various sites to run them concurrently.Reliability: If one site fails in a distributed system, the remaining sites can potentiallycontinue operations.Communication: There are many instances in which programs need to exchange datawith one another. Distributed data base system is an example of this.Real-time Operating SystemThe advent of timesharing provided good response times to computer users. However,timesharing could not satisfy the requirements of some applications. Real-time (RT)operating systems were developed to meet the response requirements of suchapplications.There are two flavors of real-time systems. A hard real-time system guarantees thatcritical tasks complete at a specified time. A less restrictive type of real time system issoft real-time system, where a critical real-time task gets priority over other tasks, andretains that priority until it completes. The several areas in which this type is useful aremultimedia, virtual reality, and advance scientific projects such as undersea explorationand planetary rovers. Because of the expanded uses for soft real-time functionality, it isfinding its way into most current operating systems, including major versions of Unix andWindows NT OS.A real-time operating system is one, which helps to fulfill the worst-case response timerequirements of an application. An RT OS provides the following facilities for thispurpose:1. Multitasking within an application.2. Ability to define the priorities of tasks.3. Priority driven or deadline oriented scheduling. 4. Programmer defined interrupts.A task is a sub-computation in an application program, which can be executedconcurrently with other sub-computations in the program, except at specific places in itsexecution called synchronization points. Multi-tasking, which permits the existence ofmany tasks within the application program, provides the possibility of overlapping theCPU and I/O activities of the application with one another. This helps in reducing its
  12. 12. elapsed time. The ability to specify priorities for the tasks provides additional controls toa designer while structuring an application to meet its response-time requirements.Real time operating systems (RTOS) are specifically designed to respond to events thathappen in real time. This can include computer systems that run factory floors, computersystems for emergency room or intensive care unit equipment (or even the entire ICU),computer systems for air traffic control, or embedded systems. RTOSs are groupedaccording to the response time that is acceptable (seconds, milliseconds, microseconds)and according to whether or not they involve systems where failure can result in loss oflife. Examples of real-time operating systems include QNX, Jaluna-1, ChorusOS,LynxOS, Windows CE .NET, and VxWorks AE, etc.Self assessment questions 1. What do the terms program, process, and thread mean? 2. What is the purpose of a compiler, assembler and linker? 3. What is the structure of a code file? What is the purpose of the symbol table in a code file? 4. Why are shared libraries essential on modern computers?Operating System ComponentsEven though, not all systems have the same structure many modern operating systemsshare the same goal of supporting the following types of system components.Process ManagementThe operating system manages many kinds of activities ranging from user programs tosystem programs like printer spooler, name servers, file server etc. Each of theseactivities is encapsulated in a process. A process includes the complete execution context(code, data, PC, registers, OS resources in use etc.).It is important to note that a process is not a program. A process is only ONE instant of aprogram in execution. There are many processes can be running the same program. Thefive major activities of an operating system in regard to process managementare1. Creation and deletion of user and system processes.2. Suspension and resumption of processes.3. A mechanism for process synchronization.4. A mechanism for process communication.5. A mechanism for deadlock handling.
  13. 13. Main-Memory ManagementPrimary-Memory or Main-Memory is a large array of words or bytes. Each word or bytehas its own address. Main-memory provides storage that can be access directly by theCPU. That is to say for a program to be executed, it must in the main memory.The major activities of an operating in regard to memory-management are: 1. Keep track of which part of memory are currently being used and by whom. 2. Decide which processes are loaded into memory when memory space becomes available. 3. Allocate and de-allocate memory space as needed.File ManagementA file is a collection of related information defined by its creator. Computer can storefiles on the disk (secondary storage), which provides long term storage. Some examplesof storage media are magnetic tape, magnetic disk and optical disk. Each of these mediahas its own properties like speed, capacity, data transfer rate and access methods.A file system normally organized into directories to ease their use. These directories maycontain files and other directions.The five main major activities of an operating system in regard to file management are 1. The creation and deletion of files. 2. The creation and deletion of directions. 3. The support of primitives for manipulating files and directions. 4. The mapping of files onto secondary storage. 5. The back up of files on stable storage media.I/O System ManagementI/O subsystem hides the peculiarities of specific hardware devices from the user. Only thedevice driver knows the peculiarities of the specific device to whom it is assigned.Secondary-Storage ManagementGenerally speaking, systems have several levels of storage, including primary storage,secondary storage and cache storage. Instructions and data must be placed in primarystorage or cache to be referenced by a running program. Because main memory is toosmall to accommodate all data and programs, and its data are lost when power is lost, thecomputer system must provide secondary storage to back up main memory. Secondarystorage consists of tapes, disks, and other media designed to hold information that will
  14. 14. eventually be accessed in primary storage (primary, secondary, cache) is ordinarilydivided into bytes or words consisting of a fixed number of bytes. Each location instorage has an address; the set of all addresses available to a program is called an addressspace.The three major activities of an operating system in regard to secondary storagemanagement are: 1. Managing the free space available on the secondary-storage device. 2. Allocation of storage space when new files have to be written. 3. Scheduling the requests for memory access.NetworkingA distributed system is a collection of processors that do not share memory, peripheraldevices, or a clock. The processors communicate with one another throughcommunication lines called network. The communication-network design must considerrouting and connection strategies, and the problems of contention and security.Protection SystemIf a computer system has multiple users and allows the concurrent execution of multipleprocesses, then various processes must be protected from one another’s activities.Protection refers to mechanism for controlling the access of programs, processes, or usersto the resources defined by a computer system.Command Interpreter SystemA command interpreter is an interface of the operating system with the user. The usergives commands with are executed by operating system (usually by turning them intosystem calls). The main function of a command interpreter is to get and execute the nextuser specified command. Command-Interpreter is usually not part of the kernel, sincemultiple command interpreters (shell, in UNIX terminology) may be supported by anoperating system, and they do not really need to run in kernel mode. There are two mainadvantages of separating the command interpreter from the kernel. 1. If we want to change the way the command interpreter looks, i.e., I want to change the interface of command interpreter, I am able to do that if the command interpreter is separate from the kernel. I cannot change the code of the kernel so I cannot modify the interface.
  15. 15. 2. If the command interpreter is a part of the kernel, it is possible for a malicious process to gain access to certain part of the kernel that it should not have. To avoid this scenario it is advantageous to have the command interpreter separate from kernel.Self Assessment Questions 1. Discuss the various components of OS? 2. Explain the Memory Management and File Management in brief. 3. Write Note on. 1. Secondary-Storage Management 2. Command Interpreter SystemOperating System ServicesFollowing are the five services provided by operating systems for the convenience of theusers.Program ExecutionThe purpose of a computer system is to allow the user to execute programs. So theoperating system provides an environment where the user can conveniently run programs.The user does not have to worry about the memory allocation or multitasking oranything. These things are taken care of by the operating systems.Running a program involves the allocating and de-allocating memory, CPU scheduling incase of multi-process. These functions cannot be given to the user-level programs. Souser-level programs cannot help the user to run programs independently without the helpfrom operating systems.I/O OperationsEach program requires an input and produces output. This involves the use of I/O. Theoperating systems hides from the user the details of underlying hardware for the I/O. Allthe users see that the I/O has been performed without any details. So the operatingsystem, by providing I/O, makes it convenient for the users to run programs.For efficiently and protection users cannot control I/O so this service cannot be providedby user-level programs.File System Manipulation
  16. 16. The output of a program may need to be written into new files or input taken from somefiles. The operating system provides this service. The user does not have to worry aboutsecondary storage management. User gives a command for reading or writing to a fileand sees his/her task accomplished. Thus operating system makes it easier for userprograms to accomplish their task.This service involves secondary storage management. The speed of I/O that depends onsecondary storage management is critical to the speed of many programs and hence Ithink it is best relegated to the operating systems to manage it than giving individualusers the control of it. It is not difficult for the user-level programs to provide theseservices but for above mentioned reasons it is best if this service is left with operatingsystem.CommunicationsThere are instances where processes need to communicate with each other to exchangeinformation. It may be between processes running on the same computer or running onthe different computers. By providing this service the operating system relieves the userfrom the worry of passing messages between processes. In case where the messages needto be passed to processes on the other computers through a network, it can be done by theuser programs. The user program may be customized to the specifications of thehardware through which the message transits and provides the service interface to theoperating system.Error DetectionAn error in one part of the system may cause malfunctioning of the complete system. Toavoid such a situation the operating system constantly monitors the system for detectingthe errors. This relieves the user from the worry of errors propagating to various part ofthe system and causing malfunctioning.This service cannot be allowed to be handled by user programs because it involvesmonitoring and in cases altering area of memory or de-allocation of memory for a faultyprocess, or may be relinquishing the CPU of a process that goes into an infinite loop.These tasks are too critical to be handed over to the user programs. A user program ifgiven these privileges can interfere with the correct (normal) operation of the operatingsystems.Self Assessment Questions
  17. 17. 1. Explain the five services provided by the operating system.Operating Systems for Different ComputersOperating systems can be grouped according to functionality: operating systems forSupercomputers, Computer Clusters, Mainframes, Servers, Workstations, Desktops,Handheld Devices, Real Time Systems, or Embedded Systems.OS for Supercomputers:Supercomputers are the fastest computers, very expensive and are employed forspecialized applications that require immense amounts of mathematical calculations, forexample, weather forecasting, animated graphics, fluid dynamic calculations, nuclearenergy research, and petroleum exploration. Out of many operating systems used forsupercomputing UNIX and Linux are the most dominant ones.Computer Clusters Operating Systems:A computer cluster is a group of computers that work together closely so that in manyrespects they can be viewed as though they are a single computer. The components of acluster are commonly, connected to each other through fast local area networks. Besidesmany open source operating systems, and two versions of Windows 2003 Server, Linuxis popularly used for Computer clusters.Mainframe Operating Systems:Mainframes used to be the primary form of computer. Mainframes are large centralizedcomputers and at one time they provided the bulk of business computing through timesharing. Mainframes are still useful for some large scale tasks, such as centralized billingsystems, inventory systems, database operations, etc.Minicomputers were smaller, less expensive versions of mainframes for businesses thatcouldn’t afford true mainframes. The chief difference between a supercomputer and amainframe is that a supercomputer channels all its power into executing a few programsas fast as possible, whereas a mainframe uses its power to execute many programsconcurrently. Besides various versions of operating systems by IBM for its earlySystem/360, to newest Z series operating system z/OS, Unix and Linux are also used asmainframe operating systems.Servers Operating Systems:Servers are computers or groups of computers that provides services to other computers,connected via network. Based on the requirements, there are various versions of serveroperating systems from different vendors, starting with Microsoft’s Servers fromWindows NT to Windows 2003, OS/2 servers, UNIX servers, Mac OS servers, andvarious flavors of Linux.
  18. 18. Workstation Operating Systems:Workstations are more powerful versions of personal computers. Like desktopcomputers, often only one person uses a particular workstation, and run a more powerfulversion of a desktop operating system. Most of the times workstations are used as clientsin a network environment. The popular workstation operating systems are Windows NTWorkstation, Windows 2000 Professional, OS/2 Clients, Mac OS, UNIX, Linux, etcDesktop Operating Systems:A personal computer (PC) is a microcomputer whose price, size, and capabilities make ituseful for individuals, also known as Desktop computers or home computersDesktop operating systems are used for personal computers, for example DOS, Windows9x, Windows XP, Macintosh OS, Linux, etc.Embedded Operating Systems:Embedded systems are combinations of processors and special software that are inside ofanother device, such as the electronic ignition system on cars. Examples of embeddedoperating systems are Embedded Linux, Windows CE, Windows XP Embedded, FreeDOS, Free RTOS, etc.Operating Systems for Handheld Computers:Handheld operating systems are much smaller and less capable than desktop operatingsystems, so that they can fit into the limited memory of handheld devices. The operatingsystems include Palm OS, Windows CE, EPOC, and SummaryAn operating system (OS) is a program that controls the execution of an applicationprogram and acts as an interface between the user and computer hardware. The objectivesof operating system are convenience, efficiency, and ability to evolve. Besides this theoperating system performs function such as hiding details of the hardware, resourcemanagement, and providing effective user interface.The process management component of operating system is responsible for creation,termination, other and state transitions of a process. The memory management unit ismainly responsible for allocation, de-allocation to processes, and keeping track records ofmemory usage by different processes. The operating system services are programexecution, I/O operations, file system manipulation, communication and error detection.Terminal Questions
  19. 19. 1. What is an operating system? 2. What are the objectives of an operating system? 3. Describe in brief, the function of an operating system. 4. Explain the evolution of operating system in brief. 5. Write a note on Batch OS. Discuss how it is differ from Multi Programmed Batch Systems. 6. What is difference between multi-programming and timesharing operating systems? 7. What are the typical features of an operating system provides? 8. Explain the functions of operating system as file manager. 9. What are different services provided by an operating system? 10. Write Note on : 1.Mainframe Operating Systems 2.Embedded Operating Systems 3.Servers Operating Systems 4.Desktop Operating Systemsmany Linux versions such as Qt Palmtop, and Pocket Linux, etc.Unit 2: Operating System Architecture : This unit deals with the Simple structure, extended machine, layered approaches. Itcovers the different methodology for OS design (Models). It covers the Introduction ofVirtual Machine, Virtual environment and Machine aggregation. And also describes theimplementation techniques.IntroductionA system as large and complex as a modern operating system must be engineeredcarefully if it is to function properly and be modified easily. A common approach is topartition the task into small component rather than have one monolithic system. Each ofthese modules should be a well-defined portion of the system, with carefully definedinputs, outputs, and functions. In this unit, we discuss how various components of anoperating system are interconnected and melded into a kernel.Objective:At the end of this unit, readers would be able to understand:
  20. 20. • What is Kernel? Monolithic Kernel Architecture • Layered Architecture • Microkernel Architecture • Operating System Components • Operating System ServicesOS as an Extended MachineWe can think of an operating system as an Extended Machine standing between ourprograms and the bare hardware.As shown in above figure 2.1, the operating system interacts with the hardware hiding itfrom the application program, and user. Thus it acts as interface between user programsand hardware.Self Assessment Questions1. What is the role of an Operating System?Simple StructureMany commercial systems do not have well-defined structures. Frequently, suchoperating systems started as small, simple, and limited systems and then grew beyondtheir original scope. MS-DOS is an example of such a system. It was originally designedand implemented by a few people who had no idea that it would become so popular. Itwas written to provide the most functionality in the least space, so it was not divided into
  21. 21. modules carefully. In MS-DOS, the interfaces and levels of functionality are not wellseparated. For instance, application programs are able to access the basic I/O routines towrite directly to the display and disk drives. Such freedom leaves MS-DOS vulnerable toerrant (or malicious) programs, causing entire system crashes when user programs fail.Of course, MS-DOS was also limited by the hardware of its era. Because the Intel 8088for which it was written provides no dual mode and no hardware protection, the designersof MS-DOS had no choice but to leave the base hardware accessible.Another example of limited structuring is the original UNIX operating system. UNIX isanother system that initially was limited by hardware functionality. It consists of twoseparable parts: • the kernel and • the system programsThe kernel is further separated into a series of interfaces and device drivers, which havebeen added and expanded over the years as UNIX has evolved. We can view thetraditional UNIX operating system as being layered. Everything below the system callinterface and above the physical hardware is the kernel. The kernel provides the filesystem, CPU scheduling, memory management, and other operating-system functionsthrough system calls. Taken in sum, that is an enormous amount of functionality to becombined into one level. This monolithic structure was difficult to implement andmaintain.Self Assessment Questions 1. ”In MS-DOS, the interfaces and levels of functionality are not well separated”. Comment on this. 2. What are the components of a Unix Operating System?Layered ApproachWith proper hardware support, operating systems can be broken into pieces that aresmaller and more appropriate than those allowed by the original MS-DOS or UNIXsystems. The operating system can then retain much greater control over the computerand over the applications that make use of that computer. Implementers have morefreedom in changing the inner workings of the system and in creating modular operatingsystems. Under the top-down approach, the overall functionality and features aredetermined and the separated into components. Information hiding is also important,because it leaves programmers free to implement the low-level routines as they see fit,provided that the external interface of the routine stays unchanged and that the routineitself performs the advertised task.
  22. 22. A system can be made modular in many ways. One method is the layered approach, inwhich the operating system is broken up into a number of layers (levels). The bottomlayer (layer 0) id the hardware; the highest (layer N) is the user interface. Users File Systems Inter-process Communication I/O and Device Management Virtual Memory Primitive Process Management Hardware Fig. 2.2: Layered ArchitectureAn operating-system layer is an implementation of an abstract object made up of data andthe operations that can manipulate those data. A typical operating – system layer-say,layer M-consists of data structures and a set of routines that can be invoked by higher-level layers. Layer M, in turn, can invoke operations on lower-level layers.The main advantage of the layered approach is simplicity of construction and debugging.The layers are selected so that each uses functions (operations) and services of onlylower-level layers. This approach simplifies debugging and system verification. The firstlayer can be debugged without any concern for the rest of the system, because, bydefinition, it uses only the basic hardware (which is assumed correct) to implement itsfunctions. Once the first layer is debugged, its correct functioning can be assumed whilethe second layer is debugged, and so on. If an error is found during debugging of aparticular layer, the error must be on that layer, because the layers below it are alreadydebugged. Thus, the design and implementation of the system is simplified.Each layer is implemented with only those operations provided by lower-level layers. Alayer does not need to know how these operations are implemented; it needs to knowonly what these operations do. Hence, each layer hides the existence of certain datastructures, operations, and hardware from higher-level layers. The major difficulty withthe layered approach involves appropriately defining the various layers. Because layercan use only lower-level layers, careful planning is necessary. For example, the devicedriver for the backing store (disk space used by virtual-memory algorithms) must be at alower level than the memory-management routines, because memory managementrequires the ability to use the backing store.Other requirement may not be so obvious. The backing-store driver would normally beabove the CPU scheduler, because the driver may need to wait for I/O and the CPU canbe rescheduled during this time. However, on a larger system, the CPU scheduler mayhave more information about all the active processes than can fit in memory. Therefore,
  23. 23. this information may need to be swapped in and out of memory, requiring the backing-store driver routine to be below the CPU scheduler.A final problem with layered implementations is that they tend to be less efficient thanother types. For instance, when a user program executes an I/O operation, it executes asystem call that is trapped to the I/O layer, which calls the memory-management layer,which in turn calls the CPU-scheduling layer, which is then passed to the hardware. Ateach layer, the parameters may be modified; data may need to be passed, and so on. Eachlayer adds overhead to the system call; the net result is a system call that takes longerthan does one on a non-layered system. These limitations have caused a small backlashagainst layering in recent years. Fewer layers with more functionality are being designed,providing most of the advantages of modularized code while avoiding the difficultproblems of layer definition and interaction.Self Assessment Questions1. What is the layered Architecture of UNIX?2. What are the advantages of layered Architecture?Micro-kernelsWe have already seen that as UNIX expanded, the kernel became large and difficult tomanage. In the mid-1980s, researches at Carnegie Mellon University developed anoperating system called Mach that modularized the kernel using the microkernelapproach. This method structures the operating system by removing all nonessentialcomponents from the kernel and implementing then as system and user-level programs.The result is a smaller kernel. There is little consensus regarding which services shouldremain in the kernel and which should be implemented in user space. Typically, however,micro-kernels provide minimal process and memory management, in addition to acommunication facility. Device File Server Client Process Virtual Memory Drivers ….
  24. 24. Microkernel HardwareFig. 2.3: Microkernel ArchitectureThe main function of the microkernel is to provide a communication facility between theclient program and the various services that are also running in user space.Communication is provided by message passing. For example, if the client program andservice never interact directly. Rather, they communicate indirectly by exchangingmessages with the microkernel.On benefit of the microkernel approach is ease of extending the operating system. Allnew services are added to user space and consequently do not require modification of thekernel. When the kernel does have to be modified, the changes tend to be fewer, becausethe microkernel is a smaller kernel. The resulting operating system is easier to port fromone hardware design to another. The microkernel also provided more security andreliability, since most services are running as user – rather than kernel – processes, if aservice fails the rest of the operating system remains untouched.Several contemporary operating systems have used the microkernel approach. Tru64UNIX (formerly Digital UNIX provides a UNIX interface to the user, but it isimplemented with a March kernel. The March kernel maps UNIX system calls intomessages to the appropriate user-level services.The following figure shows the UNIX operating system architecture. At the center ishardware, covered by kernel. Above that are the UNIX utilities, and command interface,such as shell (sh), etc.
  25. 25. SelAssessment Questions 1. What other facilities Micro-kernel provides in addition to Communication facility? 2. What are the benefits of Micro-kernel?UNIX kernel ComponentsThe UNIX kernel has components as depicted in the figure 2.5 bellow. The figure isdivided in to three modes: user mode, kernel mode, and hardware. The user modecontains user programs which can access the services of the kernel components usingsystem call interface.The kernel mode has four major components: system calls, file subsystem, processcontrol subsystem, and hardware control. The system calls are interface between userprograms and file and process control subsystems. The file subsystem is responsible forfile and I/O management through device drivers.
  26. 26. The process control subsystem contains scheduler, Inter-process communication andmemory management. Finally the hardware control is the interface between these twosubsystems and hardware. Fig. 2.5: Unix kernel componentsAnother example is QNX. QNX is a real-time operating system that is also based on themicrokernel design. The QNX microkernel provides services for message passing andprocess scheduling. It also handled low-level network communication and hardwareinterrupts. All other services in QNX are provided by standard processes that run outsidethe kernel in user mode.Unfortunately, microkernels can suffer from performance decreases due to increasedsystem function overhead. Consider the history of Windows NT. The first release had alayered microkernels organization. However, this version delivered low performancecompared with that of Windows 95. Windows NT 4.0 partially redressed the performanceproblem by moving layers from user space to kernel space and integrating them moreclosely. By the time Windows XP was designed, its architecture was more monolithicthan microkernel.Self Assessment Questions 1. What are the components of UNIX Kernel? 2. Under what circumstances a Micro-kernel may suffer from performance decrease?
  27. 27. ModulesPerhaps the best current methodology for operating-system design involves using object-oriented programming techniques to create a modular kernel. Here, the kernel has a set ofcore components and dynamically links in additional services either during boot time orduring run time. Such a strategy uses dynamically loadable modules and is common inmodern implementations of UNIX, such as Solaris, Linux and MacOSX. For example,the Solaris operating system structure is organized around a core kernel with seven typesof loadable kernel modules: 1. Scheduling classes 2. File systems 3. Loadable system calls 4. Executable formats 5. STREAMS formats 6. Miscellaneous 7. Device and bus drivers Such a design allow the kernel to provide core services yet also allows certain features to be implemented dynamically. For example device and bus drivers for specific hardware can be added to the kernel, and support for different file systems can be added as loadable modules. The overall result resembles a layered system in that each kernel section has defined, protected interfaces; but it is more flexible than a layered system in that any module can call any other module. Furthermore, the approach is like the microkernel approach in that the primary module has only core functions and knowledge of how to load and communicate with other modules; but it is more efficient, because modules do not need to invoke message passing in order to communicate. Self Assessment Questions 1. Which strategy uses dynamically loadable modules and is common in modern implementations of UNIX? 2. What are different loadable modules based on which the Solaris operating system structure is organized around a core kernel?Introduction to Virtual MachineThe layered approach of operating systems is taken to its logical conclusion in theconcept of virtual machine. The fundamental idea behind a virtual machine is to abstractthe hardware of a single computer (the CPU, Memory, Disk drives, Network InterfaceCards, and so forth) into several different execution environments and thereby creatingthe illusion that each separate execution environment is running its own private
  28. 28. computer. By using CPU Scheduling and Virtual Memory techniques, an operatingsystem can create the illusion that a process has its own processor with its own (virtual)memory. Normally a process has additional features, such as system calls and a filesystem, which are not provided by the hardware. The Virtual machine approach does notprovide any such additional functionality but rather an interface that is identical to theunderlying bare hardware. Each process is provided with a (virtual) copy of theunderlying computer.Hardware Virtual machineThe original meaning of virtual machine, sometimes called a hardware virtualmachine, is that of a number of discrete identical execution environments on a singlecomputer, each of which runs an operating system (OS). This can allow applicationswritten for one OS to be executed on a machine which runs a different OS, or provideexecution “sandboxes” which provide a greater level of isolation between processes thanis achieved when running multiple processes on the same instance of an OS. One use is toprovide multiple users the illusion of having an entire computer, one that is their“private” machine, isolated from other users, all on a single physical machine. Anotheradvantage is that booting and restarting a virtual machine can be much faster than with aphysical machine, since it may be possible to skip tasks such as hardware initialization.Such software is now often referred to with the terms virtualization and virtual servers.The host software which provides this capability is often referred to as a virtual machinemonitor or hypervisor.Software virtualization can be done in three major ways:· Emulation, full systemsimulation, or “full virtualization with dynamic recompilation” — the virtual machinesimulates the complete hardware, allowing an unmodified OS for a completely differentCPU to be run.· Paravirtualization — the virtual machine does not simulate hardware butinstead offers a special API that requires OS modifications. An example of this isXenSource’s XenEnterprise (www.xensource.com)· Native virtualization and “fullvirtualization” — the virtual machine only partially simulates enough hardware to allowan unmodified OS to be run in isolation, but the guest OS must be designed for the sametype of CPU. The term native virtualization is also sometimes used to designate thathardware assistance through Virtualization Technology is used.Application virtual machineAnother meaning of virtual machine is a piece of computer software that isolates theapplication being used by the user from the computer. Because versions of the virtual
  29. 29. machine are written for various computer platforms, any application written for thevirtual machine can be operated on any of the platforms, instead of having to produceseparate versions of the application for each computer and operating system. Theapplication is run on the computer using an interpreter or Just In Time compilation. Oneof the best known examples of an application virtual machine is Sun Microsystem’s JavaVirtual Machine.Self Assessment Questions1. What do you mean by a Virtual Machine?2. Differentiate Hardware Virtual Machines and Software Virtual Machines.Virtual EnvironmentA virtual environment (otherwise referred to as Virtual private server) is another kind ofa virtual machine. In fact, it is a virtualized environment for running user-level programs(i.e. not the operating system kernel and drivers, but applications). Virtual environmentsare created using the software implementing operating system-level virtualizationapproach, such as Virtuozzo, FreeBSD Jails, Linux-VServer, Solaris Containers, chrootjail and OpenVZ.Machine AggregationA less common use of the term is to refer to a computer cluster consisting of manycomputers that have been aggregated together as a larger and more powerful “virtual”machine. In this case, the software allows a single environment to be created spanningmultiple computers, so that the end user appears to be using only one computer ratherthan several.PVM (Parallel Virtual Machine) and MPI (Message Passing Interface) are two commonsoftware packages that permit a heterogeneous collection of networked UNIX and/orWindows computers to be used as a single, large, parallel computer. Thus largecomputational problems can be solved more cost effectively by using the aggregatepower and memory of many computers than with a traditional supercomputer. The Plan9Operating System from Bell Labs uses this approach.Boston Circuits had released the gCore (grid-on-chip) Central Processing Unit (CPU)with 16 ARC 750D cores and a Time-machine hardware module to provide a virtualmachine that uses this approach.Self Assessment Questions1. What is Virtual Environment?
  30. 30. 2. Explain Machine Aggregation.Implementation TechniquesEmulation of the underlying raw hardware (native execution)This approach is described as full virtualization of the hardware, and can be implementedusing a Type 1 or Type 2 hypervisor. (A Type 1 hypervisor runs directly on the hardware;a Type 2 hypervisor runs on another operating system, such as Linux.) Each virtualmachine can run any operating system supported by the underlying hardware. Users canthus run two or more different “guest” operating systems simultaneously, in separate“private” virtual computers.The pioneer system using this concept was IBM’s CP-40, the first (1967) version ofIBM’s CP/CMS (1967-1972) and the precursor to IBM’s VM family (1972-present).With the VM architecture, most users run a relatively simple interactive computingsingle-user operating system, CMS, as a “guest” on top of the VM control program (VM-CP). This approach kept the CMS design simple, as if it were running alone; the controlprogram quietly provides multitasking and resource management services “behind thescenes”. In addition to CMS, VM users can run any of the other IBM operating systems,such as MVS or z/OS. z/VM is the current version of VM, and is used to supporthundreds or thousands of virtual machines on a given mainframe. Some installations useLinux for zSeries to run Web servers, where Linux runs as the operating system withinmany virtual machines.Full virtualization is particularly helpful in operating system development, whenexperimental new code can be run at the same time as older, more stable, versions, eachin separate virtual machines. (The process can even be recursive: IBM debugged newversions of its virtual machine operating system, VM, in a virtual machine running underan older version of VM, and even used this technique to simulate new hardware.)The x86 processor architecture as used in modern PCs does not actually meet the Popekand Goldberg virtualization requirements. Notably, there is no execution mode where allsensitive machine instructions always trap, which would allow per-instructionvirtualization.Despite these limitations, several software packages have managed to providevirtualization on the x86 architecture, even though dynamic recompilation of privilegedcode, as first implemented by VMware, incurs some performance overhead as comparedto a VM running on a natively virtualizable architecture such as the IBM System/370 orMotorola MC68020. By now, several other software packages such as Virtual PC,VirtualBox, Parallels Workstation and Virtual Iron manage to implement virtualizationon x86 hardware.
  31. 31. On the other hand, plex86 can run only Linux under Linux using a specific patchedkernel. It does not emulate a processor, but uses bochs for emulation of motherboarddevices.Intel and AMD have introduced features to their x86 processors to enable virtualizationin hardware.Emulation of a non-native systemVirtual machines can also perform the role of an emulator, allowing software applicationsand operating systems written for computer processor architecture to be run.Some virtual machines emulate hardware that only exists as a detailed specification. Forexample: • One of the first was the p-code machine specification, which allowed programmers to write Pascal programs that would run on any computer running virtual machine software that correctly implemented the specification. • The specification of the Java virtual machine. • The Common Language Infrastructure virtual machine at the heart of the Microsoft .NET initiative. • Open Firmware allows plug-in hardware to include boot-time diagnostics, configuration code, and device drivers that will run on any kind of CPU.This technique allows diverse computers to run any software written to that specification;only the virtual machine software itself must be written separately for each type ofcomputer on which it runs.Self Assessment Questions1. What are the techniques to realize Virtual Machines concept?2. What are the advantages of Virtual Machines?Operating system-level virtualizationOperating System-level Virtualization is a server virtualization technology whichvirtualizes servers on an operating system (kernel) layer. It can be thought of aspartitioning: a single physical server is sliced into multiple small partitions (otherwisecalled virtual environments (VE), virtual private servers (VPS), guests, zones etc); eachsuch partition looks and feels like a real server, from the point of view of its users.The operating system level architecture has low overhead that helps to maximize efficientuse of server resources. The virtualization introduces only a negligible overhead andallows running hundreds of virtual private servers on a single physical server. In contrast,
  32. 32. approaches such as virtualisation (like VMware) and paravirtualization (like Xen orUML) cannot achieve such level of density, due to overhead of running multiple kernels.From the other side, operating system-level virtualization does not allow runningdifferent operating systems (i.e. different kernels), although different libraries,distributions etc. are possibleSelf Assessment Questions1. Describe the Operating System Level Virtualization.SummaryThe virtual machine concept has several advantages. In this environment, there iscomplete protection of the various system resources. Each virtual machine is completelyisolated from all other virtual machines, so there are no protection problems. At the sametime, however, there is no direct sharing of resources. Two approaches to provide sharinghave been implemented. A virtual machine is a perfect vehicle for operating systemsresearch and development.Operating system as extended machine acts as interface between hardware and userapplication programs. The kernel is the essential center of a computer operating system,i.e. the core that provides basic services for all other parts of the operating system. Itincludes interrupts handler, scheduler, operating system address space manager, etc.In the layered type architecture of operating systems, the components of kernel are builtas layers on one another, and each layer can interact with its neighbor through interface.Whereas in micro-kernel architecture, most of these components are not part of kernel butacts as another layer to the kernel, and the kernel comprises of essential and basiccomponents.Terminal Questions 1. Explain operating system as extended machine. 2. What is a kernel? What are the main components of a kernel? 3. Explain monolithic type of kernel architecture in brief. 4. What is a micro-kernel? Describe its architecture. 5. Compare micro-kernel with layered architecture of operating system. 6. Describe UNIX kernel components in brief. 7. What are the components of operating system? 8. Explain the responsibilities of operating system as process management. 9. Explain the function of operating system as file management. 10. What are different services provided by an operating system?
  33. 33. Unit 3: Process Management :This unit covers the process management and threads. Brief about the process creation,termination, process state and process control. Discussed about the process VsThreads, Types of threads etc.IntroductionThis unit discuss the definition of process, process creation, process termination, processstate, and process control. And also deals with the threads and thread types.A process can be simply defined as a program in execution. Process along with programcode, comprises of program counter value, Processor register contents, values ofvariables, stack and program data.A process is created and terminated, and it follows some or all of the states of processtransition; such as New, Ready, Running, Waiting, and Exit.A thread is a single sequence stream within in a process. Because threads have some ofthe properties of processes, they are sometimes called lightweight processes. There aretwo types of threads: user level threads (ULT) and kernel level threads (KLT), user levelthreads are mostly used on the systems where the operating system does not supportthreads, but also can be combined with the kernel level threads. Threads also have similarproperties like processes e.g. execution states, context switch etc.Objectives :At the end of this unit, you will be able to understand the : What is a Process? Process Creation , Process Termination, Process States, Process Control Threads Types of Threads
  34. 34. What is a Process?The notion of process is central to the understanding of operating systems. The termprocess is used somewhat interchangeably with ‘task’ or ‘job’. There are quite a fewdefinitions presented in the literature, for instance A program in Execution. An asynchronous activity. The entity to which processors are assigned. The ‘dispatchable’ unit.And many more, but the definition “Program in Execution” seem to be most frequentlyused. And this is a concept we will use in the present study of operating systems.Now that we agreed upon the definition of process, the question is, what is the relationbetween process and program, or is it same with different name or when the process issleeping (not executing) it is called program and when it is executing becomes process.Well, to be very precise. Process is not the same as program. A process is more than aprogram code. A process is an ‘active’ entity as oppose to program which consideredbeing a ‘passive’ entity. As we all know that a program is an algorithm expressed in someprogramming language. Being a passive, a program is only a part of process. Process, onthe other hand, includes: Current value of Program Counter (PC) Contents of the processors registers Value of the variables The process stack, which typically contains temporary data such as subroutineparameter, return address, and temporary variables. A data section that contains global variables. A process is the unit of work in a system.In Process model, all software on the computer is organized into a number of sequentialprocesses. A process includes PC, registers, and variables. Conceptually, each processhas its own virtual CPU. In reality, the CPU switches back and forth among processes.Process CreationIn general-purpose systems, some way is needed to create processes as needed duringoperation. There are four principal events led to processes creation. Systeminitialization. Execution of a process Creation System call by a running process. A user request to create a new process. Initialization of a batch job.
  35. 35. Foreground processes interact with users. Background processes that stay in backgroundsleeping but suddenly springing to life to handle activity such as email, webpage,printing, and so on. Background processes are called daemons. This call creates an exactclone of the calling process.A process may create a new process by executing system call ‘fork’ in UNIX. Creatingprocess is called parent process and the created one is called the child processes. Onlyone parent is needed to create a child process. This creation of process (processes) yieldsa hierarchical structure of processes. Note that each child has only one parent but eachparent may have many children. After the fork, the two processes, the parent and thechild, initially have the same memory image, the same environment strings and the sameopen files. After a process is created, both the parent and child have their own distinctaddress space.Following are some reasons for creation of a process 1. User logs on. 2. User starts a program. 3. Operating systems creates process to provide service, e.g., to manage printer. 4. Some program starts another process.Creation of a process involves following steps: 1. Assign a unique process identifier to the new process, followed by making new entry in to the process table regarding this process. 2. Allocate space for the process: this operating involves finding how much space is needed by the process and allocating space to the parts of the process such as user program, user data, stack and process attributes. The requirement of the space can be taken by default based on the type of the process, or from the parent process if the process is spawned by another process. 3. Initialize Process Control Block: the PCB contains various attributes required to execute and control a process, such as process identification, processor status information and control information. This can be initialized to standard default values plus attributes that have been requested for this process. 4. Set the appropriate linkages: the operating system maintains various queues related to a process in the form of linked lists, the newly created process should be attached to one of such queues.
  36. 36. 5. Create or expand other data structures: depending on the implementation, an operating system may need to create some data structures for this process, for example to maintain accounting file for billing or performance assessment.Process TerminationA process terminates when it finishes executing its last statement. Its resources arereturned to the system, it is purged from any system lists or tables, and its process controlblock (PCB) is erased i.e., the PCB’s memory space is returned to a free memory pool.The new process terminates the existing process, usually due to following reasons: • Normal Exit Most processes terminates because they have done their job. This call is exit in UNIX. • Error Exit When process discovers a fatal error. For example, a user tries to compile a program that does not exist. • Fatal Error An error caused by process due to a bug in program for example, executing an illegal instruction, referring non-existing memory or dividing by zero. • Killed by another Process A process executes a system call telling the Operating Systems to terminate some other process.Process StatesA process goes through a series of discrete process states during its lifetime. Dependingon the implementation, the operating systems may differ in the number of states a processgoes though. Though there are various state models starting from two states to nine states,we will first see a five states model and then seven states model, as lower states modelsare now obsolete.Five State Process ModelFollowing are the states of a five state process model. The figure 3.1 show these statetransition. • New State The process being created. • Terminated State The process has finished execution.
  37. 37. • Blocked (waiting) State When a process blocks, it does so because logically it cannot continue, typically because it is waiting for input that is not yet available. Formally, a process is said to be blocked if it is waiting for some event to happen (such as an I/O completion) before it can proceed. In this state a process is unable to run until some external event happens. • Running State A process is said to be running if it currently has the CPU, which is, actually using the CPU at that particular instant. • Ready State A process is said to be ready if it use a CPU if one were available. It is run-able but temporarily stopped to let another process run.Logically, the ‘Running’ and ‘Ready’ states are similar. In both cases the process iswilling to run, only in the case of ‘Ready’ state, there is temporarily no CPU available forit. The ‘Blocked’ state is different from the ‘Running’ and ‘Ready’ states in that theprocess cannot run, even if the CPU is available.Following are six possible transitions among above mentioned five statesTransition 1 occurs when process discovers that it cannot continue. If running processinitiates an I/O operation before its allotted time expires, the running process voluntarilyrelinquishes the CPU.This state transition is: Block (process): Running → Blocked.Transition 2 occurs when the scheduler decides that the running process has run longenough and it is time to let another process have CPU time.This state transition is:
  38. 38. Time-Run-Out (process): Running → Ready.Transition 3 occurs when all other processes have had their share and it is time for thefirst process to run againThis state transition is: Dispatch (process): Ready → Running.Transition 4 occurs when the external event for which a process was waiting (such asarrival of input) happens.This state transition is:Wakeup (process): Blocked → Ready.Transition 5 occurs when the process is created.This state transition is: Admitted (process): New → Ready.Transition 6 occurs when the process has finished execution.This state transition is:Exit (process): Running → Terminated.SwappingMany of the operating systems follow the above shown process model. However theoperating systems which does not employ virtual memory, the processor will be idle mostof the times considering the difference between speed of I/O and processor. There will bemany processes waiting for I/O in the memory, and exhausting the memory. If there is noready process to run; new processes can not be created as there is no memory available toaccommodate new process. Thus the processor has to wait till any of the waitingprocesses become ready after completion of an I/O operation.This problem can be solved by adding to more states in the above process model by usingswapping technique. Swapping involves moving part or all of a process from mainmemory to disk. When none of the processes in main memory is in the ready state, theoperating system swaps one of the blocked processes out onto disk in to a suspend queue.This is a queue of existing processes that have been temporarily shifted out of mainmemory, or suspended. The operating system then either creates new process or brings aswapped process from the disk which has become ready.
  39. 39. Seven State Process ModelThe following figure 3.2 shows the seven state process model in which uses abovedescribed swapping technique.Apart from the transitions we have seen in five states model, following are the newtransitions which occur in the above seven state model. • Blocked to Blocked / Suspend: If there are now ready processes in the main memory, at least one blocked process is swapped out to make room for another process that is not blocked. • Blocked / Suspend to Blocked: If a process is terminated making space in the main memory, and if there is any high priority process which is blocked but suspended, anticipating that it will become free very soon, the process is brought in to the main memory. • Blocked / Suspend to Ready / Suspend: A process is moved from Blocked / Suspend to Ready / Suspend, if the event occurs on which the process was waiting, as there is no space in the main memory. • Ready / Suspend to Ready: If there are no ready processes in the main memory, operating system has to bring one in main memory to continue the execution. Some times this transition takes place even there are ready processes in main memory but having lower priority than one of the processes in Ready / Suspend state. So the high priority process is brought in the main memory. • Ready to Ready / Suspend: Normally the blocked processes are suspended by the operating system but sometimes to make large block free, a ready process may be suspended. In this case normally the low priority processes are suspended.
  40. 40. • New to Ready / Suspend: When a new process is created, it should be added to the Ready state. But some times sufficient memory may not be available to allocate to the newly created process. In this case, the new process is sifted to Ready / Suspend.Process ControlIn this section we will study structure of a process, process control block, modes ofprocess execution, and process switching.Process StructureAfter studying the process states now we will see where does the process reside, and whatis the physical manifestation of a process?The location of the process depends on memory management scheme being used. In thesimplest case, a process is maintained in the secondary memory, and to manage thisprocess, at least small part of this process is maintained in the main memory. To executethe process, the entire process or part of it is brought in the main memory, and for that theoperating system need to know the location of the process. Process identification Processor state information Process control information User Stack Private user address space (program, data) Shared address space Figure 3.3: Process ImageThe obvious contents of a process are User Program to be executed, and the UserData which is associated with that program. Apart from these there are two major partsof a process; System Stack, which is used to store parameters and calling addresses forprocedure and system calls, and Process Control Block, this is nothing but collection ofprocess attributes needed by operating system to control a process. The collection of userprogram, data, system stack, and process control block is called as Process Image asshown in the figure 3.3 above.Process Control Block
  41. 41. A process control block as shown in the figure 3.4 bellow, contains various attributesrequired by operating system to control a process, such as process state, program counter,CPU state, CPU scheduling information, memory management information, I/O stateinformation, etc.These attributes can be grouped in to three general categories as follows: Processidentification Processor state information Process control informationThe first category stores information related to Process identification, such as identifierof the current process, identifier of the process which created this process, to maintainparent-child process relationship, and user identifier, the identifier of the user on behalfof who’s this process is being run.The Processor state information consists of the contents of the processor registers, suchas user-visible registers, control and status registers which includes program counter andprogram status word, and stack pointers.The third category Process Control Identification is mainly required for the control of aprocess. The information includes: scheduling and state information, data structuring,inter-process communication, process privileges memory management, and resourceownership and utilization. pointer process state process number program counter registers memory limits list of open files . . . Figure 3.4: Process Control BlockModes of Execution
  42. 42. In order to ensure the correct execution of each process, an operating system must protecteach process’s private information (executable code, data, and stack) from uncontrolledinterferences from other processes. This is accomplished by suitably restricting thememory address space available to a process for reading/writing, so that the OS canregain CPU control through hardware-generated exceptions whenever a process violatesthose restrictions.Also the OS code needs to execute in a privileged condition with respect to “normal”: tomanage processes, it needs to be enabled to execute operations which are forbidden to“normal” processes. Thus most of the processors support at least two modes of execution.Certain instructions can only be executed in the more privileged mode. These includereading or altering a control register such as program status word, primitive I/Oinstruction; and memory management instructions.The less privileged mode is referred as user mode as typically user programs are executedin this mode, and the more privileged mode in which important operating systemfunctions are executed is called as kernel mode/ system mode or control mode.The current mode information is stored in the PSW, i.e. whether the processor is runningin user mode or kernel mode. The mode change is normally done by executing changemode instruction; typically after a user process invokes a system call, or whenever aninterrupt occurs, as these are operating system functions and needed to be executed inprivileged mode. After the completion of system call or interrupt routine, the mode isagain changed to user mode to continue the user process execution.Context SwitchingTo give each process on a multiprogrammed machine a fair share of the CPU, a hardwareclock generates interrupts periodically. This allows the operating system to schedule allprocesses in main memory (using scheduling algorithm) to run on the CPU at equalintervals. Each time a clock interrupt occurs, the interrupt handler checks how much timethe current running process has used. If it has used up its entire time slice, then the CPUscheduling algorithm (in kernel) picks a different process to run. Each switch of the CPUfrom one process to another is called a context switch.A context is the contents of a CPU’s registers and program counter at any point in time.Context switching can be described as the kernel (i.e., the core of the operating system)performing the following activities with regard to processes on the CPU: (1) suspendingthe progression of one process and storing the CPU’s state (i.e., the context) for thatprocess somewhere in memory, (2) retrieving the context of the next process frommemory and restoring it in the CPU’s registers and (3) returning to the location indicatedby the program counter (i.e., returning to the line of code at which the process wasinterrupted) in order to resume the process. The figure 3.5 bellow depicts the process ofcontext switch from process P0 to process P1.
  43. 43. Figure 3.5: Process switchingSelf Assessment Questions: 1. Discuss the process state with its five state process model. 2. Explain the seven state process model. 3. What is Process Control ? Discuss the process control block. 4. Write note on Context Switching.A context switch is sometimes described as the kernel suspending execution of oneprocess on the CPU and resuming execution of some other process that had previouslybeen suspended.A context switch occurs due to interrupts, trap (error due to the current instruction) or asystem call as described bellow: • Clock interrupt: when a process has executed its current time quantum which was allocated to it, the process must be switched from running state to ready state, and another process must be dispatched for execution. • I/O interrupt: whenever any I/O related event occurs, the OS is interrupted, the OS has to determine the reason of it and take necessary action for that event. Thus the current process is switched to ready state and the interrupt routine is loaded to do the action for the interrupt event (e.g. after an I/O interrupt the OS moves all the processes which were blocked on the event, from blocked state to ready state, and blocked/suspended to ready/suspended state). After completion of the interrupt related actions, it is expected that the process which was switched, should be brought for execution, but that does not happen. At this point the
  44. 44. scheduler again decides which process is to be scheduled for execution from all the ready processes afresh. This is important as it will schedule any high priority process present in the ready queue added during the interrupt handling period. • Memory fault: when virtual memory technique is used for memory management, many a times it happens that a process refers to a memory address which is not present in the main memory, and needs to be brought in. As the memory block transfer takes time, another process should be given chance for execution and the current process should be blocked. Thus the OS blocks the current process, issues an I/O request to get the memory block in the memory and switches the current process to blocked state, and loads another process for execution. • Trap: if the instruction being executed has any error or exception, depending on the criticalness of the error / exception and design of operating system, it may either move the process to exit state, or may execute the current process after a possible recovery.System call: many a times a process has to invoke a system call for a privileged job, forthis the current process is blocked and the respective operating system’s system call codeis executed. Thus the context of the current process is switched to the system call code.Example: UNIX ProcessLet us see an example of UNIX System V, which makes use of a simple but powerfulprocess facility that is highly visible to the user. The following figure shows the modelfollowed by UNIX, in which most of the operating system executes within theenvironment of a user process. Thus, two modes, user and kernel, are required. UNIXuses two categories of processes: system processes and user processes. System processesrun in kernel mode and execute operating system code to perform administrative andhousekeeping functions, such as allocation of memory and process swapping. Userprocesses operate in user mode to execute user programs and utilities and in kernel modeto execute instructions belong to the kernel. A user process enters kernel mode by issuinga system call, when an exception (fault) is generated or when an interrupt occurs.
  45. 45. A total of nine process states are recognized by the UNIX operating system as explainedbellow • User Running: Executing in user mode. • Kernel Running: Executing in kernel mode. • Ready to Run, in Memory: Ready to run as soon as the kernel schedules it. • Asleep in Memory: Unable to execute until an event occurs; process is in main memory (a blocked state). • Ready to Run, Swapped: Process is ready to run, but the swapper must swap the process into main memory before the kernel can schedule it to execute. • Sleeping, Swapped: The process is awaiting an event and has been swapped to secondary storage (a blocked state). • Preempted: Process is returning from kernel to user mode, but the kernel preempts it and does a process switch to schedule another process. • Created: Process is newly created and not yet ready to run.