You are on page 1of 100
‘A Gulde For Engineering Students OPERATING SYSTEMS SUBJECT CODE: 217521 S.E. (Artificial Intelligence & Data Science) Semester - Ill © Copyright with Technical Publications All publishing rights (printed and ebook version) reserved with Technical Publications No port of this book should be reproduced in any form, Electronic, Mechanical, Photocopy or any information storage and retrieval system without prior permission in writing, from Technical Publicotions, Pune. Published by : Amit Residency, Office No.1, 412, Shoniwor Peth, Pune - 411030, M.S. INDIA Ph.: +91-020-24495496/97 Email: info@technicolpublications.in Website: swwwtechnicalpublications.in Printer : Yosiej Printers & Binders, Sr.No. 10/1A,Ghule Industial Estate, Nanded Village Road, Tal. - Havel, Dist. - Pune - 411041. ISBN 978-93-5585-227-4 wu 9789355859974 [1] w © scanned with OKEN Scanner SYLLABUS Operating Systems - (217521) Credit Examination Scheme : 03 Mid_Semester (TH) : 30 Marks End_Semester (TH) : 70 Marks UnitI Fundamental Concepts of Operating system Operating system functions and characteristics, historical evolution of operating systems, issues in operating system design, User's view of the OS, Types of OS : Batch, time sharing, multiprogramming, distributed, network and real-time systems, Operating-System Services, Types of System Calls, System Programs. BASH Shell scripting : Basic shell commands, shell as a scripting language. (Chapter - 1) Unit II Process Management Process concept, Process Control Block(PCB), Process Operations, Process Scheduling : Types of process schedulers, Types of scheduling : Preemptive, Non preemptive. Scheduling’ algorithms : FCFS, SIF, RR, Priority, Inter process Communication(IPC). Threads : multithreaded model, implicit threads, threading issues. (Chapter - 2) Unit HI Process Coordination . Synchronization : Principles of Concurrency, Requirements for Mutual Exclusion, Mutual Exclusion ; Hardware Support, Operating System Support (Semaphores and Mutex), Programming Language Support (Monitors). Classical synchronization problems : Readers/Writers Problem, Producer and Consumer problem, Inter-process communication (Pipes, shared memory : system V) Deadlock : Deadlock Characterization, Methods for Handling Deadlocks, Deadlock Prevention, Deadlock Avoidance, Deadlock Detection, Recovery from Deadlock. (Chapter - 3) (ii) © scanned with OKEN Scanner Unit IV Memory Management’ Memory Management : Memory Management Requirements, Memory Partitioning : Fixed Partitionmg, Dynamic Partitioning, Buddy System, Relocation, - Paging, ‘Segmentation. Virtual Memory : Hardware and Control Structures, Operating System Software. (Chapter - 4) Unit V_V/O and File Managemient VO Management : VO Devices, Organization of /O function, VO Buffering, Disk SchedulingDisk Scheduling policies like FIFO, LIFO, STTF, SCAN, C-SCAN. File Management : Concept, Access methods, Directory Structure, Protection, File System implementation. . Directory Implementation, Allocation methods, Free Space management. (Chapter - 5) Unit VI Linux History Of Unix and Linux , Overview Of Linux - Linux Goals, Interfaces to Linux, The Shell, Linux Utility Programs, Kemel structure, Processes in Linux - Process ‘management system calls in Linux, Implementation of process and threads in Linux, Process scheduling Linux, Booting. (Chapter - 6) (vy © scanned with OKEN Scanner TABLE OF CONTENTS Chapter - 1 Fundamental Concepts of Operating System (1-1) to (1 - 24) 1.1 Operating System Functions and Characteristics . 1.2. Historical Evolution of Operating Systems. 1.3. Types of OS... 1.4 Operating-System Services 1.5 Types of System Calls. 1.6. System Programs..... 1.7 BASH Shell Scripting. Chapter -2 Process Management @- 1) to @- 32) 2.1. Process Concep' 2.2 Process Operations. 2.3. Process Scheduling. 2.4 Types of Scheduling 2.5 Scheduling Algorithms... 2.6 IPC... 2.7. Threads... wv) © scanned with OKEN Scanner 2.8 Multithreading Model Unit il Chapter-3 Process Coordination (3-1) to (3-3. 2.9 Threading Issue... 3.1. Synchronization ; Principles of Concurrericy .. 3.2. Mutual Exclusion : Hardware Support. 3.3. Operating System Support : Semaphores and Mutex... 3.4 Programming Language Support : Monitors... 3.5. Classical Synchronization Problems.. 3.6 Inter-Process Communication 3.7 Deadlock... 3.8 Deadlock Prevention. 3.9 Deadlock Avoidance... 3.10 Deadlock Detection and Recovery from Deadlock Chapter -4 Memory Management (4-1) to (4-31) 4.1 Memory Management Requirements... 4.2. Memory Partitionin, and Dynamic Partitioning... : Fixed Partitioning 4S io Buddy System .. 4.4 Paging. (vi) © scanned with OKEN Scanner 4.5. Segmentation. 4.6 Virtual Memory : Hardware and Control Structures . 4,7. Operating System Softwar Chapter-5 I/O and File Management (5 - 1) to (5 - 39) 5.1 1/0 Devices, Organization of I/O Function... 5-1 5.2 1/0 Buffering... 5.3 Disk Scheduling.. 5.4. File Management Concept. 5.5 Access Methods... 5.6 Directory Structure... 5.7. Protection... 5.8 File System Implementation .. 5.9 Directory Implementation .. 5.10 Allocation Methods... 5.11 Free Space Management Chapter-6 Linux (6-1) to (6-18) 6.1. History of Unix and Linux. 6-2 6.2 Shell... 6-3 6.3. Linux Utility Programs and Kernel Structure, 6-4 a See © scanned with OKEN Scanner 6.4. Processes in Linux. 6.5 Booting Solved Model Quest aPopers SSM F Oe “4 © scanned with OKEN Scanner Fundamental Concepts of Operating System Operating System Functions and Characte: Q.1 What is operating system ? State and explain the basic functions of operating system. Ans.: © OS definition : Operating System is a program that controls the execution of application programs. It is an interface between applications and hardware. © OS provides different types of view. For user, it is abstract view because it provides features which are important for users. OS is intermediary between user and the computer system. The major design goals/ functions of an operating system are : 1. Efficient use of a computer system 2. User convenience 3. Ability to evolve © An operating system is software that manages the computer hardware. The hardware must provide appropriate mechanisms to ensure the correct operation of the computer system and to prevent user programs from interfering with the proper operation of the system. Efficient use © For efficient use of resources, it must be monitored by operating system. Proper scheduling of resources is also required. |e Computer contains different type's resources like CPU, memory and /O. device etc. Proper monitoring is required on these resources to avoid the overhead. As per the resource, scheduling is required. © scanned with OKEN Scanner aden COMPAS Operating soy | PU and memory. If memory , wen for Cl is tention #0 ss han reew program into the Memory, They on oe Scam sat be by ence User convenient jc afected by computing environment of the re wi 4 manure of computations ner other systems ane ~a ts interfaces with by is we recur and we change the computing environment of page factors ae considered while considering yt stem. 1 Good service 2. Base of use 3. New programming moj 4. Eyoluion 5. User friendly OS. Aallity to evolve ed in such a way as to permit the effec 4 An OS should be constructed in su : ite development, testing and introduction of new system functions without au the same time interfering with service, a2 Describe in detail the functions of OS as a resource manager, ‘ans: © A computer is a set of resources, These resource provides ‘aris fintions tothe use. Functions like data movement, storing of ‘ogra, operation on data are control by an operating system, + Fig. Q21 shows OS as a resource manager. «The opering system is responsible for managing the all resources, A portion of the OS is in main memory. This portion of the OS is called er + User program and data is also stored in remaining parts of the memory, ‘Allocation of matin memory is controlled by operating system withthe ‘ip of memory management hardware. q * VO device is contolled by OS and it decides when an UO device can be wed by progam in execution, Processor is one type of resource and OS conto the execution of user program on the processor. 4 Operating Systems 1-3 _ Fundamental Conceyts of Operating System UO contoler 5 Processor #2” |... #4 Computor system protecting the memory, UO d Resource management in Time and space are the tw. the benefits of resource abstraction ? + Resource abstraction is the process of "hiding the details of how erates, thereby making computer hardware relatively easy ion programmer to use". It provide a single abstract disk interface which will be the same for both the hard disk and floppy disk. * Saves the programmer from needing to leam the dewils of both hardware interfaces a a oy A Gude for Engineering Students illite, © scanned with OKEN Scanner pod Fondamentat Concert of OMTENG Spttig Indware ier 10 = While making va eet over the Iardware by Riding some Hii functionality behind the wbstractcn specie tevel 1 Since most appheation programmers 0 cnr, the abstraction very wefel * Evolution of Operating Syst 32 : Historical Evolution of Operatl ig Systems _ 24 Dincuss evolotion of operating systems Ama : Opeming systems hive been evolving through the Following table shows the history of OS. years, Gonnraton Electronic devices Types of OS and Fes second ‘Thine —__1968-1980 Foush Sine 1980 1.3: Types of OS 5 Describe in brief the evolution of operating system, ‘Ans. + The evolution of operating systems is directly dependent 10 the evelopment of computer systems and how users use them. OS created to process jobs in batches. Later Multitasking and Time-Sharing created to run auhiple jobs and allow user interaction to improve efficiency. Mulitsking trought challenges t0 manage VO operations required by tukipe jobs in which computer vendors resolved with interups 4. Batch systom : ‘Batch system process a collection of jobs, called a batch. Batch is a sequence of usr jobs we, resource ahitraction sigs | rot need such & high level of | Frovided by the operating SYHtem is generally 128 Rantenatet Comey of Oporeting SI petting Seite 1 fob is 4 predefined vequenee of commande, programe and date that ate gembined into single anit ote joe om the Beach A ater ue Batch is independent of sion by conseracting # Sle ith 8 « Bach job define a job control speci sequence of commands spend op preening 4 Jobs with similar needs were batched together Card readers and tape deives are the input device = Dutch Output devices are tape drives, card punches an «primary function of the batch system is to 3 cone after another without requiring the operators intr fo need for human/user interaction with the job when i runs the information required to complete job is kept st « Some computer systems only did one thing at a time. instructions to camry out and these would be ccsried out one afta che ‘other, This is called a serlal system. The mechanics of development ‘and preparation of programs in such environments ate quite slow ot ‘numerous manual operations involved in the process ie the je fe Batch monitor is used to implement batch processing spstem, Sask monitor is also called kermel, Kernel resides in one pat of Se computer main memory. 2. Multiprogramming OS : + CPU remains idle in batch system. At any time either CPU or LO device was idle in batch system. To keep CPU busy. programfjob must be loaded for exceution, It increases she CPU izations. So multiprogramming increases the CPU wnltzation. Resource management is the main sim of multiprogramming operating system, File system, command provessor, LO contol system and transient area are the esscrcal components of a single wser operating system. ‘© Multprogramming operating system divides the transient area to store the multiple programs and provides resource management to the operating system. Sees ‘A Gulde for Englceing Stents Guide for Engincrng Students ot sail @ scanned with OKEN Scanner Program? e Pesan Fig. 2.5.1 Multiprograr "8 OS memory layout Hard dee (Secondary storage devia Fig. 5.2 Working of muitiprogramming OS ‘In multiprogramning operating system, programs are competing fr resources. A function ofthe multiprogramming operating system is CPU scheduling, memory management and UO management ‘A Gude for Enginering Ses cone of OPE ay, et Concepts of Operating System: ‘operating Sus are four programs for execution. All four programs are the memory. CPU select first program for execution. «contain instruction for CPU and UO operation. ‘Also explain advantages and «suppose there Joaded into t ‘Normally program qe Explain time sharing system. disadvantages: sees + « in an nteracive system, many users diel itera with te ‘ter from terminals connected t0 the computer rvecesea?’s time which is shred among multiple users simusaneonsly is termed as time-sharing. «eTime sharing is logical extension of multprogramming OS. Fie Q61 shows time sharing system. Termine! F Terinal Terminal Fig. Q.6.1 Time sharing ‘s Time sharing is a method that allows multiple users to share resources ‘at the same time. Multiple users in various locations can use a specific computer system at a time ‘e Time sharing is essentially @ rapid time division multiplexing of the processor time among several processes. The processor switching is so frequent that it almost seems each process. has its own dedicated processor. ‘= Time sharing OS is designed to provide a quick response to ssub-requests made by users. 4© The processor time is shared between multiple users at time, The processor allows each user program to execute for a small time quantum. Moreover, time sharing systems use multiprogramming and multitasking. “A Gue for Engineering Students lili @ scanned with OKEN Scanner 6__Fandamentel Coney 0f Opting prtig Sets sides immediate feedback The opting ten ov © te ae ree as bei seconds, EPA 0D the mune, ot 3 se The scheduling tecnigue wed by 0 time-sharing Kemel is cag robin scheduling with time slicing. isthe time slice eapses before the process completes sericn subreques, the kernel pre-empts the PFOCESS, MOVES it tothe eng”, “ scheduling queue and schedules another process, of The main ciflrence between Mul-programmed Batch Syston, Time-Sharing Systems is that in case of Multi-programm tyme. te dete ist maximize processor use, wheres ig Sharing Systems, the objective is 1o minimize response time «Features of time sharing system 1. User interaction with program is possible, 2. Tine sang system uses medium tem scheduling suchas rad robin fo the foreground 3. Each acer is given time slice for executing job in round rae fashion + Advantages of time sharing operating systems : 1. Provides the advantage of quick response. 2. Avoids duplication of software. 3. Reduces CPU idle time + Disadvantsges of time sharing operating systems : 1, Problem of relisblty, 2. Question of security and integrity of user programs and data. 3. Problem of data communication 7 What do you mean spooling ? Explain in detail Aas.» When & job completes execution, its i : execution, its memory is released and te pee {or the job gets copied into an outputs pool for later printing. * Spooling en acronym for simultaneo ls = 8 peripheral operation on lie pooling uses the disk as lage butler for outputing data to pris = = A Guide for Enpncering Sens operating Systems 1-9 __ Fundamental Concept of Operating Sy wed and other devices. It can also be used for input, but is for output lis main use is to prevent two users ftom alternating printing lines to the line printer on the same page, getting their output completely mixed together. It also helps in reducing idle time and overlapped LO and PU et refers to putting jobs in a buffer, a special area in memory or on a disk where a device can access them when itis ready « Spooling is useful because device access data at different rates. The buffer provides a waiting station where data can rest while the slower device catches up. ‘© Computer can perform VO in parallel with computation, it becomes possible to have the computer read a deck of cards to a tape, drum or disk and to write out to a tape printer while it was computing. This process is called spooling. “©The most common spoolit application is print spooling. Spooling batch system were the first and are the simplest of the muliprogramming systems. ‘In spooling, VO of one job is overlapped with the computation of Fone job another job. For example, a spooler at a time may tead input and at the same time, it may also print the ousput of another job. + Spooling can also process data at the remote sites. The spooler only has to notify when a process gets completed at the remote site so that spooler can spool next process to the remote side device * Spooling increases the performance of the system by increasing the working rate of the devices. It naturally leads 10 multiprogramming. Advantages of spooling ‘* The spooling operation uses a disk as a very large buffer » Spooling is however capable of overlapping UO operation for one job with processor operations for another job. “A Guide for Engincering Sudewts lit @ scanned with OKEN Scanner unanentsl Cont of Operating ng Operating Systems 1-70 ‘aa Give the featres of real ime operating system and time ghyy, operating system. 7 ‘Ans, : Features of Real Time Operating System = 4. Realtime system fails if it does not give result within the time ting 2 Real nets cannot Keep wang for Inger time without alloggi keel +3, Real time operating system uses priority scheduling algorithm, 1. User interaction with program is possible in time sharing oper system. q 2, Time sharing system uses medium term scheduling such a rouyg robin for the foreground. given time slice for executing 29 Explain distributed OS with neat sketch and give its pros ang cons. ‘Ans. Distributed operating systems depend on networking for th peration. Distributed OS runs on and controls the resources of mule ‘machines. It provides resource sharing across the boundaries of a single igle machine OS. Distributing k like a virtual uniprocessor ; to its users like an ordinary operating system but runs on multiple, independent cpu. + Fig. Q9.1 shows the distributed system, ; scatewsy Flg, 0.9.4 Distributed system Ss SS A Guide for Engineering Sudens dvantages of dstribued 08: 1. Resource sharing : Sharing of Ibvaries, database and hardware resources such as hard disks, printers and CDROM can also be done in a very effective way among all the computers and the users f software resources such as software fers to the degree of tolerance against "Availability is one of the important refers to the fraction of time for done hard disk fails or is unavailable, the program can use some other hard disk. 3, Better price performance ricroprocessor and in price-performance ratio. 4, Shorter responses times and higher throughput. ‘5 Incremental growth : To extend power and functionality of « system ‘by simply adding additional resources fo the system, «+ Examples of distributed operating system are amoeba, chrous, mach and v-syster. Difficulties in distributed OS are 1, There ate no current commercially successful examples. sad can dominate computation costs. io: Reduction in the price of computing power gives good logical extension of the multiprogramming operating . systems. interaction with ‘program is possible in time sharing operating system. During execution of the program, user interacts directly with the program, with more than one progam aa time For example, wer could be working with information from one database on the screen analyzing data, while the computer is sorting information from another database, while a excel sheet is performing calculations on a separate worksheet. ei eer a “Tou Egeng Sens © scanned with OKEN Scanner Fundementel Concepts of Operating 8 Set, sem simultaneously in wer share the computer SYS SI ly in time gp ‘Tame sharing system uses multipogramming oe es sept FOEIN h meme TE operating system. scheduling, Bach wer has at I se sharing systems, e2ch ohn cer is given a sime slice f0r fea tenh executing hisTer job in round — robin fashion. Job continues until the time slice ends. «Fig. Q.10.1 shows multitasking 08 ‘= Concept of viral machine is sed in time sharing system. It creates virtual machine one Pet thet, User interaction with system by using virtual machine, ves the command fr viral machine and result will received back Fig. 2.10.4 Multitasking og wer. «Time sharing system is more complex than multiprogranming operating system, It also takes help of filesystem. File system is stored on te disk so disk management is also requited «+ Major problem sith time sharing system is protection and security of at ‘Time shating system uses medium term scheduling such as round rota for the foreground, Background process users can use a differen, scheduling method, ‘Difference between multprogramming and multitasking operating system is context switching. In multiprogramming system a contet switching oseurs only when the currently executing process stalls for some reasons. Time sharing system gives each user the impression tat te ete sem i dts o ht we, Context switching singly flows seve aplions to be open, but only one is working a 8 ee “A Gull or Engincerig Sade | opting Stems ;_ onty one application prageam Truly speaking. even in true mi runaing at anyone inst switches ffom one program to the next programs seer fo run simultaneously att What is realtime OS 7 Explain its types with salable ecuple ‘s Time constraints is the key parameter is real time systems Jy as robots, satellites. ait tant. Because the ail he progam © a Ans. controls ationomous system suc and hydroelectric dams. 4s When user gives an input t0 the syste Timit and resut is sent back, Real time system result within the time mits, fem is any information processing system which has © vat stimuli within a finite and it must process sith fails if it does not give A realtime syst respond to externally generated inp specified period «Realtime systems are of two types : Hard and soft 1, Hard Real Time Systems A hard realtime system is one where the response specified as an absolute" value. This time is normally dictated the environment, A system is called a hard reabtime if tasks always must execution before their deadlines ct if message always delivered within a specified time interval. «+ Hard real-time is oflen associated with safety critical applications ‘A failure (eg. missing a deadline) in a safety-critical application can lead to loss of human life or severe economical damage, nish be 2, Soft Real Time Systema «© A soft real-time system is one where the response time is normally specified as an average value, This time is normally dictated by business or market, ‘© A. single computation arriving late is ot significant 1 operation of the system, though many late amvals might be « Soft realtime means that only the precedence and sequcoce for the task-operations ate defined, interrupt Iniensies and context latencies are small but there can be few deviations gt Oui or ngnerng Sens illic. @ scanned with OKEN Scanner Fundamental Concepts of Operating System Operating Systems 1-18 ‘peoween expected latencies of the tasks and observed time constraints and a few deadline misses are accepted [114 : operating-System Services 0.12 State and explain different services provided by an operating system. Ans. + 1. Prograt the memory by operat its start execution, . Input ~ output operation : Program is combination of input and cuiputsotement, While executing the program, it requires UO device 3, Error detection : Error is related to the memory, CPU, W/O device ‘and in the user program, Memory is full, stack overflow, file not found, directory not exist, printer is not ready, attempt to access illegal ‘memory are the example of error detection File and directory operation : User wants to read and writes the file and directory 'S. Communication : Communication may’ be inter-process communication and any other type of communication. Data transfer is ‘one type of communication, — 1.5 : Types of System Calls 13 What is system call ? Explain working of system call, ‘Aus. « System calls provide the interface between a running program and the operating sytem. Any single CPU computer can execute only one insivction ata time. Ifa process is running a user program in user mode and needs system service, such as reading a data from a fil, it has to execute a tap instruction to transfer control to the operating system. + Operating system provides services and system call provides interface to these services. System call is written in language C and CH as routines, System calls are performed in a series of steps. sn execution : Before executing the program, it is loaded into ing system. Once program loads into memory, 1+ System calli a technique by which a program executing in user mode a request the keml's service 15 Fundamental Concepts of Operating System operating Systems 1 terface is a function definition that # An application programmer specifies how to obtain a-given service. «# Fig, Q.13.1 shows the working of system call, User im ‘system Call() ‘Applcaion programming interface |__| ‘System cal interface User modelspace Kemel medelspace Free i Main memory Fig, Q.13.1 Working of system call “A Gilde for Engineering Sedona “A Ge for Engineering Stents @ scanned with OKEN Scanner Operating Systems 1-16 Fundamental Concepts of Operating System «When application program calls the stub, tap instruction is executeg and CPU switches to superior rode. Each system call contains it identification number + 5 maintains the twble of system call number. Operating. system executes the system call using that number. “e When the function competes, it switches the processor to user mode and then retus contol to the user process. A system call san elt request to the Kemel mode via softy Then user mode process invokes a system call, the CPU interupt. W ajchos to kemel mode and starts the execution ofthe Kemel funtion, «Making a gtem cil i ike making & special kind of procedure cat, Only system call eners the Kemel and procedure call does not enter int the kere. «Kernel implements many diferent types of system calls. The user mode roves mist pass a parameter called the system call mumber to identity, fhe required system call, All system calls setur an integer value, Inthe emel, positive or O values denote a successful termination of the system call and negative values denote an errr condition. ‘014 Explain three general method for passing parameters to the os. ‘Ans: Three general methods are used to pass parameters to the operating syste a Pass parameters in registers Registers pass starting addresses of blocks of parameters Parameters canbe placed or pushed onto the stack by the program and popped off the stack by the OS. aed 45 Discuss types of system calls. System cal is divided into following types : 1, File management 2. Process management 3, Imerprocess communication 4. VO device management 5; Information processing and maintenance Aas. : A Gale for Engineering Students opening Systeme __1-17 _ Fundamental Concept of Operating System 4, File management « File management system calls are create fil, file, read fie, write file, get ad set fle attribute se() system all, File mame with ‘and deleting a file through system fons on the delete file, open file, close User can create a file using creat autributes are required for creating ‘all, After creating a file, user can performs various operat file ‘© Read, waite, reposition are the ed after finished using. Same type of operation is operation performed on the file. File is ‘performed on clos directory. # Every file has file attributes. of file, accounting: information ete. To perform any op file, set fle atsibute and get file attribute executed to check the attributes. 2, Process management ‘system calls for process management are create, terminate, load, ‘execute, abort, set and get process attributes. Other system call for process, manegement is wait for time, wait event, allocate and free memory. In some situation user want to terminate the currently running process abnormally then system call used. Other reasons for abnormal process termination are error message generated, memory dump, error trap. + Operating system provides debugging facility to determine the problem of dump, Dump is written to secondary storage disk. ‘« Debugger is @ one type of system program. It provides facility for finding and correcting bug. 3, Interprocess communication ‘Pipe, socket, message passing and shared memory are used for interprocess communication, Send message, receive message, create and delete connection, attach remote device are the system calls used in {nterprocess communication. File attsibutes includes name of file, Pe eration on the “A Gude for Engincerng Students itaiicllllliiay @ scanned with OKEN Scanner 1s Fundamental Concepts of Operating System Operating Systems ‘Shared memory : A. process uses memory for communication. ‘Ong ‘process will create a memory portion which other processes can access, ‘A shared segment can be attached multiple times by the same process, Shared memory is the fastest form of IPC bevause data does not need to be copied between processes jcation device that can be used to] © A socket is a bidirectional comenuni ‘communicate with another process on he’same machine or with a cm oe len ee eo coi se nt ding pe sme, Mee ite oa a Fepeneaiony « Sysem cals for device management are request ( ) device release () Sr oh ee en ee ai ina Van pon Des nt wo res Hs a ee rejected. Once request is granted, control is transfer to the process a cast 5 te in ti sp a A a ee eirsekat ora iat dee ota oe oe vn ape cfgaa lb we etnta nin toa eden 1.6 : System Programs 246 Write short note on system programs. ‘Ans. : # Modern operating system consists of a collection of system Programs. System program that provides an application programming environment on top of the hardware. Some of them are simply user interfaces to system cals. They can be divided ino these categories: Operating Systems 1-19 Fundamental Concepts of Operating System 1. File management 2, Status information 3, File modification 4, Programming language support 5, Program loading and execution 6, Communications File management programs are used to create, delete, copy, rename, list, dump on files and directory. Status information system programs covers the date, time, disk space, available memory and users. All this information is formatted and displayed on output device or printed. Text editors are used for file modification. In this, new file is created and content of file is modified. Programming language support includes ‘the compilers, assemblers, interpreters for common programming language like C, C++, Java, Visual Basic. ‘© For program loading and execution, it is loaded into memory then program is executed by processor. Operating system provides different types loaders and linkers to complete execution operation. ‘« Debugging facility is provided by the operating system with the help of application program. It is used for checking errors. ‘+ Communication between two devices are performed by creating temporary connection. Communication is in between process, users and other VO devices, File transfer, remote login, electronic mail, browsing web, downloading multimedia data are the example-of communication. BASH Shell Scripting 147 What is Linux BASH shell ? Ans. © The Linux Bash is alo known as ‘Boure-agtin Shell’ It i @ command language interpreter for the Linux based system. It is a replacement of Bourne sll). 4 The LimoiUinix shell allows us_to interact with the Linux system through the commands It let us invoke an executable file to create 8 running process. exons ‘A Gulde for Engineering Stadents “A Guide for Engineering Sets @ scanned with OKEN Scanner Operating Systems 1-20 __ Fundamental Conepts of Operating System 1 Linux file system. It is designed jg 4 It also allows us to interact with th : I so allows ws 0 intact wi he on tough Bash such a way that we can perform all voyage inte a ell 2S # POE ee ee and flow control, like other| ne en te, Seas oda re Be cong see dex cleo an rn ning some 8 ea i) Chmod ii) Grep Cat iy) Sort. : iy med : Access perissons associated wit a file or directory A Co lemma Poms ed i {file can be changed only by the owner of the fie. nec wih fling emis 2 ec 2) ian 1 1120 pene FE pre i, be Fe Ova i psy whom perio 9 mgd Pe ea eminn wich te ged 2 te in to eee ve 2 acre wich pina 0 cage natn you cng te FAP fra specie pe Te eae fot Sed + pone < Pts 3 se, = indicates File Owner, "4 = indicates tht the permission is to be given, '¥ = indicates the read permission and prime.e is the filename, 1) Grop : It stands for “Get Regular Expression and Print”. The grep command allows user to search one file or multiple files for lines tht contain a pattern, The syntax is ‘sep [options] pattem. [les] Operating Systems 1-21 Fundamental Concepts of Operating System ti Cat : The cat command will also display file contents to a screen file contents to a screen. Syntax : cat filename Also, use eat for quickly creating a short file, by entering the following. $ cst > floname’ ‘After pressing the retum Key, type in the text. To save and exit the file, press CTRL-D. ‘An additional feature of eat is that it allows you to concatenate two files together by entering the following $ cat fle 1 >> file 2 ‘This command appends file to end of file 2 Iw) Sort : ‘The sort utility sorts the lines in a file By default, it sorts the file in, ASCII order, with numbers preceding alphabetic characters. Syntax: sort filename © You can also use the sort command in combination with other commands using pipes. To sort the output from a who command, center $ who | sort 2.19 Explain the significance of following shell commands 4) in i) we il) umask iv) cut v) grep ‘Ans. :i) in: The in command is used to create links. Links are a kind of shorteuts to other files. The general form of command is : S In TARGET LINK_NAME, + There are two types of links, soft links and hard links. By default, hard links are created. If you want to create soft link, use -s option. In this example, both types of links are created for the file ustlisting, In ustisting har_inke S In -s ustlsting soft fink Sisd total 12 eos “A Gale for Engineering Students “A Gul forEnginerng Students @ scanned with OKEN Scanner ean Fundamental Concepts of OPER System 1 raph righ 02012 creer 1 rah ragh 0 2012-0706 14:20 BED 2 raha eagh 491 2012-0706 1423 hhard_link a 12.07-09 14:00 soft link >ustlisting lever. 1 1 raghu raph 10 20 Tag gh 49 2012-07-06 1602 STORY 2 sgh ah 491 2012-07-06 1423 ust 07-06 14:20 filet Options ¢ av Gives the word count Counts the number of ines e : Count the number of characters: Ir gen wibut any parce the command displays all the thee coun. li) umask cum is a number which defines the default permissions which are not to be given on a file, A umask of 022 means not to give the write permission to the group(022) and others(022) by defaul The umask command automatically sets the file permissions upon creation ofthe file «The command changes initial Permission of newly created fle, The value of the argument can be calculated by subtracting the mode ‘you want as defiut from the current default mode, ‘Assume the cuent defzult mode is 0666 and you want it as 0644 then (666 - 644 = 022 will be the parameter which we have to pass with ‘umask command. Sumask 0 - sets default mode which is 0666 Wy) out ‘Cut command in unix (or imax) is used to select sections of text ftom cach line of files. You can use the cut command to select fields or SO “A Guid for Eiginering Students Operating Systems 1-23 Fundamental Concepts of Operating Sesto columns from a line by specifying a delimiter or you can select @ portion of text by specifjing the range or characters. « Basically the cut command slices a line and extracts the text. $ cut -fal filename} Where -¢ characters +f field no 4 field soparstor $ cut -c2-5 sample cuts characters from 2 to 5 fiom file sample. vy grep : Refer Q.14. 0.20 Explain the following shell commands with example + ‘grep ili) touch iv) Is. 1) ech Ans. 4) echo : echo is a builtin command in the bash and C shells that writes its arguments to standard output. The syntax: for echo is : ‘echo foption(] [string(s)] ‘A string is any finite sequence of characters (i.e, letters, ‘numerals, symbols and punctuation marks) ii) grep : Refer QUIS, ii touch + The touch command allows us to update the timestamps on existing files and directories as well as creating new, empty files. IF user are a Terminal - savvy person, user can quickly create a new file {in the command line through the following command : . $ touch "filename" Iw) Ist Is lists the contents of a directory. If no target directory is given, then the contents of the current working directory are displayed. So, if the current working directory is /, $s ‘© Actually, Is doesn't show you all the entries in a directory - Files and directories that begin with a dot (.) are hidden. The reason for this is that files that begin with a. usually contain important configuration information and should not be changed under normal éircumstances. “A Gale for Engineering Students @ scanned with OKEN Scanner ‘Fundamental Concepts of Operating System operating Systems 28 ‘921 State command line arguments im shell with example, sean aepumens or vals ay be passed 10 shell Sp. Simpy [Unit W pas se cegments on te comand Hine when runing a sell serpy a pe goon ofthe Command run (stall the name op se pel erp fle, SIs the feat argument $2 isthe second ergumen, 3 is the third argument et. ane warble $¥ consis the umber of command Iie AEUMERG th vvaable S* contains all the arguments at onog were supplied and the the number of command Tine arguments passed ‘The variable S# reports to the shell script program. shell script to print all argument with script name ample : Create ¢ co iguments passed. Create seript file commline sh and total number of at using following content ‘# vim comininesh # bin/bash ‘echo Sept Name: "$0" ‘echo Total Number of Argument Passed: 'S#" Process Management | 2.1 : Process C Differentiate between a process and a program. Tans: « Process isan active entity that requires a set of resoules, artding « processor, program counter, registers to perform its function. Multiple processes may be associated with one program. «Process means a program in execution. Process execution mi in sequential order. bifference between Process and Program : at Define process. mst progress echo Arguments List - Process Program echo 1. $1 ‘Docum bb wath 3 ert pa OCH ie Proc i civ iy. rogram spss ay eae Proc isa sequrnee of | Prog conte he | ea kate ingrcton executions. inststins i Process exists in a ‘A progam exists at single | limited span of time, place and continues to. | END... a E | Proves isa dynamic Program sa sia en, 2 How PCB helps in process state management ? Explain the structure of PCB. ‘Ans. : Process control block ‘Operating system Keeps an intemal data structure to describe each process it manages: When OS creates process, it creates this process a "er Egg Sat ae @ scanned with OKEN Scanner : — a descriptor, In some operating: Process identification So Pees Cont Bee tng O21 so pom aoe process control block: « Process control block will change | Program counter sccording to the operating system. PCB is also called task control block, The PCB is identified by an integer Process ID (PID). When a process is running, its hardware state is inside the CPU, When the OS stops running a process, it saves the registers values in the PCB, When a process is. created by operating system, it allocates a PCB for it. OS initializes PCB and puts PCB on the correct queue. Following information is stored in Fig. @.24 Process control block process control bloek. 1, Process identification : Each process is uniquely identified by ty users identfiation and a pointer connecting it to its descriptor. 2. Priority aumber : Operating system allocates the priority number each process. According to the priority number it allocates ty 43. Program counter : The PC indicates’ the address of the ne insruction to be executed for this curent process. 4. Memory allocation : It contains the value of the base registen limit registers and the page tables depending on the memory systen used by the operating system, 5. VO status information : It maintains information about the oper files, list of VO devices allocated tothe process et. Memory allocation VO stats information ‘Accounting information Number of registers Process state ‘A Gude for Engineering Suen Process Management hes Process uses number of files for operation. It opened file by this process of the state : new, ready Operating Systems 6, List of open files + Proces Operating system Keeps tack of 1 Process state : Process may be in any running. and waiting terminate a3 Draw and explais process state diagram. ‘Anse ¢ «Each process has an execution state which indiates what process ‘prbaently doing. The process desriptor is the basic data structure Sel i epresent the specific tate for each process. Fig, Q.3.1 shows a proc state diagram. aed CPU alloc Controlled by ___OPU scheduler Fig, Q.3.1 Process state diagram The process states are as follows : 1. New : Operating system creates new process by using fork{ ) system call, These process are newly ereated process and resources are not allocated 2. Ready : The process is competing for the CPU. Process reaches to the head of the list (queue). 3. Running : The process that is currently being executed. Operating system allocates all the hardware and software resources to the process for execution Gade for Engineering Sudents @ scanned with OKEN Scanner Operating Systens 4 Bloeked / Waiting + A proces is wating util some evento such a the competion ofan input-output operation 5. nit /End : A process i completes is operations and releases i reures ] Process Operations (22 te Q.4 Explain process creation process. ‘Ams. : « Operating system creates the process in following situations : 1. Staring of new batch job. 2. User request for reating new process 3. To provide new services by OS. 4 System call from curently runing proces. peraing stem creates a new process with the specified or defi ‘atiibues and identifier, A process may create several new subprocess, «Parent process is crating process and the new proteses are called te children ofthe process. When operating system creates proces, it builds the data strcture for managing process and allocates address space ig primary main memory «Operating system crests foreground and backround process. Process i identified by unique process identifier (PID) in UNIX and windows, ‘operiting system. PID value isan integer number. ll processes in UNIX are created using the fork( ) system call. The forking process is called the parent process. The new process is called the child proces. + Both the parent and child process have their own and private memory (Open files are shared between parent and child If the parent changes the value of its variable, the modification will ‘only affect the variable in the parent process's address space. Other address spaces created by fork() calls will not be affected even though they have identical variable names. — ‘A Guide for Engineering Students Operating Systems 25 Process Management When a process is created, OS assigns some attributes. These ate priority, privilege level, requirement of memory, acess righ, memory protection, PID etc. To perform operation, process needs software and fuardware resources, It includes CPU time, files, memory, VO device. «Relation between parent process and child process is as follows 1 Parent process continues to execute concurently with its child process. 2, Parent process’ waits until some or all of its chilren have tecminated. void main() : { printf Operating System\n' fork print{(Technical Publications\n') rotum 0; } «+ In above program Operating System is printed only once and Technical Publications is printed two times. {5 List the four events that cause processes to be created. Explain ‘each in brief. ‘Ans. : There are four events that cause processes to be created they are, 1, System initialization (Process creation at boot time), 2, Execution of @ process creation system call by a running process, 3. A user request fo create a new process, 4, Initiation of a batch job. «Several processes are created when the computer is booted. «+ Process Creation System Call : A running process issue system calls to create one or more new processes to help it do its job, When the work ‘can be divided between several related, but otherwise independent interacting processes. For example, process fetches data from the intemet and stores it in a shared buffer, another process, processes this ata, “A Guide for Engineering Sudens @ scanned with OKEN Scanner + Proce May 6 Explain various ‘reasons of process termination. its normal execution then that ys. ; » When process finishes its nor Process i fos wn eS pa oe) eo ty proces, ener) space Wes He aac ed xt 1 tepals den ag the process, At the same time, it deallocate all the resources hold tis pees + Flowing 1. Noma epeion of epson Memory nt stale Tine ce exited Pat eion Faire of VO Regus fom pret FOES Mist of sce gis | 23 : Process Scheduling | 2.3 Process Schedullng | 7 Define the following ) Scheduling queue b) Device que «) Ready queue ‘ans :2) Scheduling queve : Scheduling queue i queue of processes oy inpetonpat devices. When the wser process enters into the system, they inate job queue. Job queue consis ofall processes ofthe sytem, b) Device queue ; Device queue is 2 queue for which mulipe processes are waiting for a particular YO device, Each device ta rainsined its own device queue. the various reasons for process termination ¢) Ready queue : The processes which sre ready and waiting ty execute are Kept in the ready queue. Ready queue is stored in main ‘memory. Linked list is used for representing ready queue, Pointer field of PCB is used for this, Operating Systems a7 Operating Sys rere Process Management | 20 Explain diferent types of schedules in operating sytem. Ans. Schedules are used to handles process scheduling. It is one type of system software and selects the jobs from the system and decide which process 10 run. Schedulers are of three types - 1. Long ferm scheduler 2. Short term scheduler 3, Medium term scheduler «Fig. Q8.1 shows queueing diagram for process scheduling. =| Long tem gehen ew prceases | Ready queue 7 ‘ J.|_Short term} | Centra nl eavey Ps] P4l Pit scneauing ~| Processing za ose Tec tt Keer (eee | eet Process. 2 intern wat TO [Queue for] completed 0. Request oi one Fig. 8.1 Process scheduling queueing diagram “AGule for Engineering Sie 1A Gu for Engineering Sade @ scanned with OKEN Scanner Process Manz ms gem rerating Syst 28 | Operating $0 scheduler - tens tom ler It determines vig job schet ‘Long term scheduler i also called j an | process are amid to the system for process nord selec vere que and loads ino the main memory fF SSN ee of sultprogramming ‘Long tem scheduling controls the GeBree °- 4 aang apts, 1 proves a baled mix offs Sh as VQ ‘pound and CPU bound gis sed in real time operating system. Time. Long tem sched aa term scheduler. sharing operating system has no long Medium term scheduler ‘s Medium term scheduler is part o removes the process ffom memory sultprogrammin. IF process makes system takes this. process becomes suspended, t cannot «tn ds sition, the process is removed ffom memory and makes fee space for other process The suspended process is stored in the second: dard disk, This process is called swapping. Short term scheduler « Short tem scheduler is also called CPU scheduler. It selects the process fom queue which are ready to execute and allocate the CPU for) execution «Shor tem scheduler is faster that long term scheduler. This scheduler rakes scheduling decisions much more frequently than the long-term or sid-term schedulers, ¢ swapping function. Sometimes jp Tt also reduces the degree of ‘an VO request and it is in memory then operating jnto suspended states, Once the process 1 make any progress towards completion, lary storage device ic, +A scheduling decision will at @ minimum have to be made after every time slice, and these are very short * Tis also known as dispatcher, — —— _____ “A Gili for Engincering Sens operating Systems 29 Process Management plain concept of context switching with the help of neat as Ex diagram. lAns. + Fig. Q9-1 shows context switching. 08: en ee | rose ‘or 10 operation ak ‘ave the process image for PT 4 Running Ready 0° Toad the process image for P2 locked Sette prossinene erF2 |x i | Ly i | Ready ning Toad the process nage for Pt | Fig. 0.9.1 Context switching +A context switch is the switching of the CPU from one process oF thread to another. A context is the contents of a CPU's registers and program counter at any point in time. «Switching the CPU to another process requires performing a state save of the current process and a state restore of a different process. This task is known as a context switch, ‘© A context switch can mean a register context switch, a task context switch, a thread context switch or a process context switch ‘© A register is a small amount of very fast memory inside of « CPU that is used to speed the execution of computer programs by providing quick access to commonly used values. A program counter is a specialized register that indicates the position of ‘the CPU in its instruction sequence and which holds either the address Gilde for Engincoring Students @ scanned with OKEN Scanner Proce Menegemey operating Stems 210 ar he isuton bing exceed ore adress of TRE MEX nnruyig | to be exeuted, depering on the specie SYM ce deseibed in more detail 88 the Keryy + Context switching. cam bs performing the following ‘hreads) on the CPU : srsseending the pogesin of one proves ad stoung the CP, tne (he,-te content) fo that process somehere in memory, ext process from memory ang elves with regard {0 prOSESSS Cnchdng 2, Revieving the context of the restoring it inthe CPUS registers and | 4. Returning tothe Toetionindsnted By the program counter in ory | to resume the proces. | « context switches ean occur only in Kemel mode (system mods) Kere| leged mode of te CPU in which ony the Kemel ring mode is a privile dra which provides aces 1 all memory locations and all other system resourees. ‘10 Explain diference between Tong term, short ferm and medium term scheduler. | Ans: Long term Short term Medium term | 1 tris sebeduler, It Js CPU scheduler. 1 i swaping, | 2 Spend is teas thn Speed is very fst, Speed isin between | short term scheduler. both | 3. teeontols the degree Less contol over Reduce the degree | of moliprogramming, degree of of rmuhipeogramming, —multiprogramming, Absent or minimal in Minin in ine Time sharing system time sharing system. sharing system, use medium tem scheduler, — operating Sates an Process Management Poa pee poses at tom ang Pen | | Thom pool and lad the processes that reintroduced into) i oer Tmo memory for ae realy wo execute. memory ands | | execu creation can be | comin 5 Process sate it Process sate is - | (New to Ready). (Ready to Running) | 1 selsta good process, Selest a new process a | mrs of 10 bound and fora CPU gale ‘CPU bound, frequently. 2a : Types of Scheduling cat What should be scheduling criteria for scheduling algorithm ? ‘Ans. : Scheduling criteria = «Depending on the system, CPU scheduling criteria will change. + CPU scheduling should attempt to service the 4. Throughput = maximum number of processes per unit time, The higher is the fhumnber, the more work is done by the system, Waiting time : The average period of time a process spends waiting, 2 Process is normally in the ready queue in waiting time. 13, Turnaround time : Turnaround time start from process submission to ‘completion of process. ‘Tumaround time = Burst time + Waiting time Response time + It is the time from the submission of a request until the first response is produced. CPU utilization + It is average function of time during which the processor is busy. 6, Fairness : Avoid the process from the starvation. All the processes ‘must be given equal opportunity to execute. Priority : If the operating system assigns priorities to processes, the scheduling mechanism should favor the higher priority processes, 4 “A Gul for Engneoring Students @ scanned with OKEN Scanner Wee ee alt Process Man "8m, remy +A gen poss oes ld T™MT ARO i | opti PPE Ee ox stem amount of time unde sil 3 ; a af operations the scheduling policy «Depending upon the ature ee fan throughput are the SYStem center Operating Systems Process Management ‘CPU scheduling, it switches from one process to another process. CPU ‘esource management is commonly known as scheduling 1g Algorithms : Scheduling slgoiims or scheduling potiies _ the provesses in the ready queue is to be allocated to the Cee decide which of sec egy onthe Pe of schedling poly and wether tht ple For scheduling arial time and Ans. eee | Giher preemptive of son-preemptive. Se Na, Preemptive scheduling, Nompreemive scheduling“) rjc ime ate also will ay 8. Nonpreemptive scheduling ensures recent ee [as taking the CPU away and time and draw a Gantt Chart illustrating the allocating i 1 another frovess execution using following scheduling algorithms. Preemptive scheduling i more complex ist come frst serve fe oe _ . | eerie wis) i SF (on = reempiv) Fo ecmpive hadng icursNoapremptve cheng does np |)? = dele : [2 Peers etc bee eco EE ean eS san | d | are wd 4 ° a EG acmatc aid béowt shes te din LO : eee eee =a boo Simple, bt vr ine | ra sg : | stage rurmaroxnd 5. Example : Round robin. Example 0.43 Define term scheduler, scheduling and scheduling algorithm with example, ‘Ans, : « Scheduler ; Schedulers are used to handles process scheduling Pr] Pe | Pr | Ps | Pe | Pe | Ps | Pr | Po | Pe | Ps | Pr Wis exe ope af sion str nd sec ke ob fom te aye wd | Eee : 1 ‘decides which process to run process of selecting processes from among : eee vee thse ques aed ou Wy aed, | i SI oompreempie : Gat chant * Scedulg + Ie a mpogamning exvirnment,-usually moe = aT programs to be executed then could possibly be nuh at one time. In ~|_* * 7 is a 7 7 = ner Era ool = “ur Eragon @ scanned with OKEN Scanner 21d ‘Waiting time and turnaround time : 044-24 13-64 19-15 =3 a BR 34114104449 _ 9g “Average wating time for RR = === OF 15464446 ‘Average waiting time for SIF = "=" = 62 2141641345413, “Average tumaround time for RR 3 136 204995010 vag turin ine a i = BEAPESSIP 9g G48 For the table given below, calculate average waiting time ang fverage turnaround time and draw a Gantt chart illustrating the process execution using following scheduling algorithms. ) i) Priority (non-preemptive). Burst Time Priority 3 5 6 2 4 3 “A Gul for Engnering Suen Man Procese Management her f) Round obi (dime slice = 2 ins) REPRE PET as Te 3 {i Priority (non - preemptive) fe [Pe ey f 1s | ee | iy gee a a8 fy pceer-usn [users ie im | [Ress al Average waiting time of Round Robin = (24945445) /5 = 64 Average waiting time of Priority (non-preemptive) =(OF1412+5+1/5=38 Average turnaround time of Round Robin (S415 +9+16+7)/5= 104 ‘Average turnaround time of Priority (non-preemptive ) A Gul for Englcering Sudents @ scanned with OKEN Scanner eeeerreeteereereeeeceeatees Process Managemen Qpertigsytong setter ss 4) SOF (oon preemptive) i) Poorty (preemptive) Process Arvival Time | Burst Time Priority i 0 9 3 1 1 2 B 2 1 t % 3 1 5 nk 4 6 4 Note : For priority scheduling, minimum value indicates higher priority. Ans. + Gantt Chart 4) SIF (aon - preemptive) operating Systems 27 Process Management ‘Waiting time and tumaround time ‘Waiting time oF Piety SE ty (ecurengtie) | reap) Gonpeenrte) Prenat) 9-0-0 0-0+10-2°9 7 7 t. Baron ty | “2e15 [2-2-0 7 B-3=0 6 1 ere “Average waiting time of SIF (non-preemptive) e(OF8415+747)/5 974 “Average waiting time of Priority (preemptive) = (84+8+0420+13)/5=98 ‘Avecage tumaround time of SIF (non-preemptive) (949 +2248413)/5= 122 Average tumaround time of Priority (preemptive ) 1749474214 20)/5= 148 Py Ps Pa Q.17 For the table given below calculate the average waiting time ° Gd average turn around time and draw a Gant chart dstraing fi pisces Wace: mcg lieing whlig pst i) Priwity (Preemptive) ‘RR (Time slice -2 units) it) SIF (aon-preemptive) TF a ae [races Aint tine Bart ine 7? +9 Temas on a | on i <4 Race 7 nee : | pen 3 => zeae “or Ege Ses @ scanned with OKEN Scanner eee Process Man pats sumed 2 gem Process Management "Ans. i) RR (lime sie = 2 wil) ETT TT CL as 8 MOEA AE ams. i) RR (Time slice = 2 units) i) SIF ( Non-preemptive) FETT PSY Pa Pa a ra PP Pa PP 7 7s a — cee SIF ( Non-preemptive) | [turnaround time it Ee Fe 2 7 Process RR SUF | | Process RR SUF b 0 © 2 = I | x as - : PI 0 0 g fe, 1 | | Waiting ti fen io j jn ie Is a mB 4 4 | bal 6 1 2 ee ie jm B i 12544 Z venge = 584 nse | sou ace" | ae | 22275 || avernge = 7944 Q.48 For the table given below calculate the average walting time - and average turn around time and draw a Gantt Chart illustrating the process execution using following scheduling algorithms. aoe 49 What is Interprocess Communication ? Explain types of IPC. 4) RR (Time slice - 2 units) i) FCS ‘Ans. 6 Exchange of data between two or more separate, independent Arrival time processesthreads is possible using IPC. Operating systems provide a 7 facilitiesresources for Inter-Process Communications (IPC), such as message queues, semaphores, and shared memory. 5 ‘© A complex programming environment often uses multiple cooperating 2 2 | processes to perform related operations, ‘These processes must communicate with each other and share resources and information. The Soe “A Gul for Enginering Sdents qos A Guide for Engineering Sudens @ scanned with OKEN Scanner cen Manas peng sytoms 4 Kemel must provide ‘mechanisms that make this ee a mechanisms ae eoleevely refed toa nterprocess communion, J fcitesesouces «© Distributed computing systems make use of thes pare pod : provide Applicaton Programming Interface (APD) wie oe ‘be programmed at a higher level of abstraction. (€-» Sm receive), 1 Five gpes of ier pros communication ea l0¥8 1. Shared memory pets proves to commaniete HY simply reading and writing to specified memory location 2. Mapped memory is similar to shared memory, except that it is tesrined ihe in the file sem 4. Pipes emit sequal communication fom one pss © a reed proses. a 4 FIFOs tre sir to pipes, except that related provestes ca, venue because the pipe is given a mae in the Hie gem 1) 5. Sockets support communication between ‘unrelated processes even on diftret compas. zo Wait purpose of IPC ? ‘Ans. : « Purposes of IPC Tr Dita trauser : One posts may wi fo send dus to anther ees 2 Sharlg data: Mul processes may wish to operate on shared dat such tnt if process motes the data, tht change willbe immednly vile ober processes ting it. 3. Event modieation + A process may wish to notify anther acess ost af process that sme event his eceured 4. Resource staring: The Kernel qrovides default semantics for resource allocation; hey ae nt suitable fer ll plication. 5 Process contol: A process such as dehuguer may wish assume complete control over the execution of another process. — 1 Gulefor Enginerng Sets operating Syste 221 Process Management ‘qzt What i pipe ? How to create pipe 2 vans. «A pipe is a uniiestonal, fsin fist-ot, unstructured data ‘An of fixed maximum size. Writers ad data tothe end of the pipe: sees reteve dat fom the font of the pipe wpnce read, the data is removed from the pipe and is unavailable 10 cher readers. A pipe provides a simple flow contol mechanism. 4A process attempting to read ffom empty pipe blocks uni mor! data is ‘writen to the pipe, A. process tying to write to 2 fll pipe lock emt ter process reads data ftom pipe. «The pipe system call creates a pipe and retums 1wo fle descriptors: one for reading and one for writing, These descriptors are inherited by child processes, which thus share aeoes othe fl «Each pipe can have several readers and writers, A given process may te a reader ot writer or both. Fig. Q21.1 shows date low through a pipe Senders Receivers Fig. 0.21.1 Data flow through a pipe « Pipes can be used only between processes that have a common ancestor. Normally, a pipe is created by a process, that process calls fork and the pipe is used between the parent and the child. @ scanned with OKEN Scanner + Example to show how to create and ‘main( ) < int pipetdl2}, char busf}100}; sf Pipe(pipetd) < 0) cexx_sys pe ers printitread fd = Xa, write fa = d\n, pipet), pipet); f (wrte(pipef alt], "hello world\n’, 12) != 12) exz_sys('write error) sf ( (aread(pipefél0}, buf, sizeot(>uff))) < =0) orr_sys(read error’); vyite (1, bull n); det =stdout*/ 3 2.7 : Threads 0.22 What is threads ? Explain advantages of threads, ‘Ans. : + Thread is a dispatchable unit of work, It consists of thread ID, program counter, stack and register set. Thread is also called a Ligh ‘Weight Process (LWP). Because they take fewer resources then a process. A thread is easy to create and destroy. ft shares many attributes of a process. Threads are scheduled on a] processor. Each thread can execute a set of instructions independent of other threads and processes. Fig. Q22.1 shows a thread, ‘Every program has at least one thread, Programs without multithreading executes sequentially. That is, after executing one instruction the next instruction in sequence is executed. ‘Thread is a basic processing unit to which an operating system allocates Processor time and more than one thread can be executing cade inside @ Process | Process Managemen Opetingspneme ‘use a pipe | 22 sytem opie SE _Proces Management Heavy weight process Register These ‘Stack Mask Daa |. ‘Addross space an Local ‘global information information Fig. Q.22.4 Throad thread advantages 4, Contest switching time is minimized, +, Thread support for efficient communication, 4, Resource sharing is possible using threads, 4A thread provides concurrency within a process. 5. is more economical to create and context switch threads, ‘a23 Differentiate between process and thread, Process is also called heavyweight process. ‘Operating system interface is required for process switching. ‘Thread is also called lightweight proces Each process oferates independently | n completly clean another of the other proces. threads stack. os ‘A Gulde for Engineering Students 7 Guile for Engineering Students pe @ scanned with OKEN Scanner

You might also like