0% found this document useful (0 votes)
3 views59 pages

OS Basic Knowledge

An Operating System (OS) serves as an intermediary between users and hardware, providing a simplified interface while managing resources efficiently. It abstracts complex hardware details, allowing applications to interact with files and devices without needing to understand the underlying complexities. The document also discusses various types of operating systems, including mainframe, server, and multiprocessor operating systems, highlighting their functions and resource management capabilities.

Uploaded by

bhoumik9212
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views59 pages

OS Basic Knowledge

An Operating System (OS) serves as an intermediary between users and hardware, providing a simplified interface while managing resources efficiently. It abstracts complex hardware details, allowing applications to interact with files and devices without needing to understand the underlying complexities. The document also discusses various types of operating systems, including mainframe, server, and multiprocessor operating systems, highlighting their functions and resource management capabilities.

Uploaded by

bhoumik9212
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
1.2 WHAT IS OPERAT Yweratine § r; 8 an it ii Operating System is a system software which acts as an intermediary Setween user and hardware. s of the hardware Operating System keeps the complicated detai i d simple interface. from the user and provides user with eas nidde performs functions which involves allocation of resources efficiently gram, file system, Input Output device. between user E-mail Music Web reader player browser i User mode Kernel mode { Figure 1. Abstract view of Operating system Reference: Modern Operating system, Fourth edition, Andrew S. Tanenbaum, Herbert Bos Explanation of Figure 1: The hardware components lies at the bottom of the diagram. It is ° considered as the most crucial part of computer system. To protect the hardware from direct access, it is kept at the lowest level of hierarchy. Hardware components includes circuits, input output device, monitor ete © Operating system runs in the kernel mode of the system wherein the OS gets an access to all hardware and can execute all machine - instructions. Other part of the system runs in user mode. Scanned with CamScanner bet me ty a tee ob a oO 1.2.2/Te Operating Sy as an Estended Maehnes «The structure of computers stem at the machine-language level is complicated {0 program, especially for input/output. Programmers don’t deal with hardware, so a level of absttaction is supposed to be maintained. + Operating systems provides layer of abstraction for using disks: files + Absiraction allows a programs to create, write, and read files, without having to deal with the messy details of how the hardware y works x + Abstraction is the key to managing all the complexity. «Good abstractions turn a nearly impossible ° k into two manageable «The first is defining and implementing the abstractions. « The second is using these abstractions to solve the problem at hand. + operating system primarily provides abstractions to application programs in a top- down view « E.g.: Itis much easier to deal with photos, emails, songs, and Web pages than with the details of these files on SATA (or other) disks. -3 The Operating System as a Resource Manager: * Modern computers consist of processors, memories, timers, disks, mice, network interfaces, printers, and a wide variety of other devices. « In the bottom-up view, the operating system provides for an orderly and controlled allocation of the processors, memories, and 1/0 devices among the various programs. Operating system allows multiple programs to be in memory and run at the same time. © Resource management includes multiplexing (sharing) resources in two different ways: in time and in space. «In time multiplexed, different programs takes tums using CPU. First one of them gets to use the resource, then the another, and so on. Sharing the printer. When multiple print jobs are queued up for printing on a single printer, a decision has to be made about which one is to be printed next © In space multiplexing, Instead of the customers taking turns, each one gets part of the resource, + E.g: main memory is divided up among several running progktnrs: So each one can be resident at the same time Scanned with CamScanner Novedwarne SS At Ae component thal tam be seam amd, touchrols cane cated. hasdowe, | - Fork of Hlavduae | msec ONSEN ; Merron To, Bevices 4 computer + “CU fetihag He wide of tone atl -bC in meme Le eu vl eas -asinsey aad pra tenn fee zal She er Writ Bode, agers a 3 —— ee eS Scanned with CamScanner ee 2 —_—?7 Storing doka ofa he of cornputen Seves-ao ‘inborface bao Hog e onc, nN ae “within TA lovst level tang : 05, Corn bi lors, Inter i rie aero emblens ek. te ee stem : l : (Designed, to pets, centre — locas spall ra proceating eabobilittes Foie ey rele cts a | : z ee J Scanned with CamScanner _Wheck th hha to_-O punaking System = i ~Ofs. oo system sfo oF 8 TE works as inberfacs. bfto Usat Tan Lrtl —stho1nct_ diet asctoning the hasdstanit in — se. thro Ss Os __d te 2 Tf they i, no O d —if Con oa to ofens 1 pautiaitns hosdiware, — = — bi have an hiN\ oe ewice. He have to se eayona healt nie sgene Ge wir coro Wer Y on. heave bo use 05. —foc—theat_necnorns.. Scanned with CamScanner Peimarey Hoh OS _ | fos : aor Peienooes 9 i lanahis ale Thread Though ral -——- Provickk, Coavieninc (ne of hao k. © (Windows o fuovidin created per. nayerhy of conwnience) Uni fof Arne —— J (Linux) : Functional hes wources Manager Tre om clbne ond, Geer : ny duster by wg Ann EE Mansa jetihel cad Ge tae ‘eaten 4? thet A . tcl atd cf oiog 4B Aesounte mona, -— But whore t a -—penalilel crewing meamy WI a aunereven ancy ~—Gtepaine 0, Susilo the tao “Retin tn mejor, __Rex_st ae CPUS on SE Ue loved. a — Algo _ - G penvesh hen on tol ef. “burs ash. pundirg. Necyatals Ao oceen pome cif. ce Ahab oink OS tb arf DS -works poo AM eam How rnuch arch ase ty be vided fb ushigh uve w mUCh Gin oUF gunk by Oo Scanned with CamScanner Memery Hon. ye (RAM) ou g iorage Monagumont | device. manag traent < = ot nt uD) o sherage Hong in > Heloted” be HD 2 ie veal Te a anentty thed _t On: constraint Wi stoval te, ew’ fo shore tok howe fox BO dake ~J un cur sys stem Aone by Fie tystem pc UNF s aed we date which S$ linux. —_____-— : peck when te broce: — ig _dyont. (ilicca end Reallccabon) (oz RAM = _ fn [iri — (ea ‘i Da, braces comblite seme iSome this brocecs h_taerk 2 | SC oeeaiggael ein ithe have peso beosrd con Accor ay fea. " rey ~Kanbaros Senet Pisce te 3 — ah Aa hes ‘Gord + Sett | so hosts “ty Sctused, Ll — Gott ne ens can Oday it Scanned with CamScanner v : ~~ ™ proces calls ov ences ony inst te Giver starrer etl, ety tel : La tho cancers it thes proeuss eed he blocked. 7 = th Thee are tee mafotw -fenctionali ey _ Haxduoans ton he _aceesed in tee va feat Sven bererr Let More knew thet OS in blaf LH = i A fybeshis ok aah Karnal ev Grnmend | “peg Soe Cal ————— —S — a > oil be exeuited a (Hew olt_te — a) ‘post. 3. Pouer_on Sel? Ter hard usasa will he teak my > Tu AloSuoll ad NBR BAM taal. be Record), a eR. “oul. “toad Bootloader tp’ RAM. =e ap po bs | bh AM Scanned with CamScanner jomdews Linux Mae Save, Palin Pistols be Tete, pack beady | hee Leder will Wad 05 to RAM jis ‘ Sof} Book ua Hand Becking ( Rentert/ acl 7 iPower dm Sypler) an Rune REEF Pony res eres fer reer TWA To Sytem Genuwl Hebrs £ fist Os fe TBH 04 temp American Avjah'sn) SHARE 05, bowed on Same Concept GH= NANO cotibl, Tint Shoatag Syclom, first tae “clevalapudl od rT vopulatre, Centon Bi 409 = (5t13 Bus oth “Haaken Confral : —f4stemn = TBM Sy clon [3¢ o- Batch prccens! 3B Hsin frome (forwer Og =—_= * a Oh oo! a Sty 39 oe al Scanned with CamScanner HALO Nulhien (Hal hy plexed Info E Computing ~ Sonvice H) —_fimes hosing based on Re concept of a single Jo level Dtnno y | S ‘ K | 369 3 UNIT ¥_a form of “mult feokin 4 re mulher cc impule OS J atthe Boll ud i Hibs S— PMeuwrch Cnter bh | ken Trampsers —pu | Nichia A Olhen _ A940 = Dos il Digital Aauihmeak Corbecation fe = Lo Pbp-n Ute ey “ert a 4 j ; j YW CL Ay hs £ Cob Acridine dtp 4 sitet Cn OS head 6 OE J i : Hulk. ten —Exeeuhy es Rein fring 1 wl: ma ds! wed MBH kasd Bat > Bork Unix boned On _Sotree recto f—exaginal 7 Nix developed be Bell Labs : ae Sache ye toto Ses Hs= Pos fo X80" be oi Hitabso . | Reb nding 02 L8H fe : DOs "Scanned with CamScanner foray 6 nal torn — | ‘est tas jo4 : 1 Hae Ds. 9 $5.2 Njodow td hye [Link] [tbe ry vm “ADL any SH origh nal a oF | 1984 Chore Hae OS deve lope d e Hee a ' = dod ere scecl -p tceal era — sac “GOT Ii nox (froin mMtni-~ UNL. | i cernpleant TA ora gs oar mere z roo ents ———belis vile NFL Tasha tw Technology teach. 2p iOS (fr Android Scanned with CamScanner a —acich OS 2 Ves Malki breq Malki tasking v Real Hine © Hondicld . bag Laing oe Hp tela the — betich of job_r mew a aig a batde_ Se weenie thu” nok 2 eecub ib Tn 19bo.7f eomion ccna fe exceuki Maine Jcrimbamtia Nk: scitnhis be ntearchs atch wed Wom. Sa foe thorn Hass mel. ‘ | tA Coa fees geeh se} Ke Hoy toed fo do wd thedue bs offline 03 Sta, Jes Thave™ te de cory collate ale (na ded thew inh offline ele ths a ~ Ratdhds> Ls jo b Und nok “pg avai “ali? evens haves Til gies jobs to ohesabis ohrater sau Het sents Snfe will be us dal. =| o Date| \ Teontal ih Scanned with CamScanner AL fedvantoge No tem nual TatenR RGR — Ohrtaber oi Maks — oti lea hind. of hodrhoe fs O wll eeu = = | Dis hora dee ga yrve mp Ne n Hi ynemory Urnitahion lok, { AL: rns beh cf Kins Qk LECRG RAK ceaedt ~ “ — ae : ing kA Hk amdan. Jada st jada —broees ta he 7 5 iy} cena : ~ Gb nen ~preembhive. ; OPC is tos idle (Tf some oroces in exceubion teem ty entha Oty To device then anether racers wild emken Ake Cfo) oe : ——Teap boi nt ta ~9 Sh CPU will execu a beoees a, Ruger! enkinaly ual procens toil) hee an tla oon tot the ~ igs Some lp od o fara bic ae = ae TE T have 10 stidenb tn dors and wok hove Squeslion 4Ron T g wilh Qo fe Student] and will! erence fy DTS qpuadstions _ Scanned with CamScanner Nas fe ert proces by Bh Untill Ho b hunny poy, theb J want te Ye. et Ga geo rally - Miah fusking [Tires ‘aang (Ex tenn ioa frog —= troombhve SS hd duidedl fe advance. thes WL execu > “a a : sores hing oa - gy eyordad, ‘a — 4 are tran “ek ofherwatse. (M Se Delays cannet by bearect . +4, Mis sib lou Viral a oe Yookoc ee 4 Scanned with CamScanner Yelributed > fe processin enviseonment | Haneda uske “Hachines tae tn aly couple A Vireo nment vere) _ men ide by has the Oln Cdusronm } Kernill Own Chigk. ete Tes eth trccare Competrhon Power. = | a Bhan bes 3 Byailab? by Pak folename. Scaleb hy [odes w have % oe inbution power Wo Cn | ines ean, tk hs 2x3, a kg Weide Hicne wave, Waskyy Ms VON we Scanned with CamScanner lesapning of thy tem 2.2 DIPPERENT OPERATING syStEM ——— 1.21 Mainframe Operating Systems used in ¥ ries Le Commerce ysterns are 5 Wransaction, ated for busines’ faviirame operating rvers dedi tems of Mainframe oper? an handle marry joD* 9 “lems are oriented 5 in ashy that at nframe Operating systems can de amount of inp [put transaction ices of mainframe operating ms are . The main sery + to handle batch processing of jobs. rocessing of multiple g multiple remote users to have an * to handle transaction p! request. + timesharing of servers allowin, access to the server. 2.2.2 Server Operating Systems: + Server Operating Systems are are dedicated servers. x and Windows are some examples of Server Operating the ones that runs on the machine which + Solaris, Linu: Systems : Server Operating Systems allows sharing of multiple resources like | hardware, files or print services Web pages are stored on a dedicated server to handle request and response. 2.2.3 Multiprocessor Operating System: rocessor Operating Sysiems are also known as 1 or multicomputer depending upon h 7 ee ted and shared. pon how multiple pr « Multip computers are connec’ 10 ee Scanned with CamScanner + These computers have high speed communication mechanism with strong connectivity + Personal computer are also ereated and embedded with the multiprocessor technology + Multiprocessor operating system give high processing speed as multiple proc 2.2.4 Personal Operating + Personal operating systems are installed in machines used by common and large number of us + They support multiprogramming, running multiple programs like games, and Internet access simultaneously on one word, ex machine. Examples Linux, Windows, Mac. 2.5 Handheld Operating System: Handheld operating systems are found in all handheld devices like Smart phone and tablets. It is also known as Personal Digital Assistant. The most popular operating systems in today"s market are android and ios. These operating systems need high processing processor. It is also embedded with different types of sensor. 2.6 Embedded Operating Systems: Embedded operating systems are designed for those devices which are not considered as computers. These operating systems are preinstalled on the devices by the device manufacturer. All pre installed softwares are in ROM and no changes could be done to it by the users. The best example of embedded operating systems is washing machines, oven etc. 2.2.7 Real-Time Operating Systems: + Real Time Operating systems have strict time constraints due to which it is used in applications that are very critical in terms of safety. + Real time operating system are classified into hard real time and soft real time + Hard real time systems have very stringent time constraints, certain actions should occur at that time only, Components are tightly coupled in hard real time * Soft real time operating system is the one where missing of deadlines some time will not cause damage ah Scanned with CamScanner >A _ prec tan, Uinmnricates with ameter — eg Ik Linker. Pre ex _Cornimuunicahtea) = —Spie a yf pagan om vets oe be ides the _Senvice Jofstg a Sst the oe: —preq vi, af} Prog Tatas, o 4 arr pest eae i cs —— Vv Urrc A lwotre| or Money emt | yk oie | Qreak Procen() 2 Cree ‘ process Exit () $ deimi nal a broces. 4 Ee Exec. . 0. +h wait Scanned with CamScanner National. fm l29+) ) ati Pipe(}) Creo Fils Mapping’) _ @) Protechun — Sok Fils Sees iby C) ibral Bile sof Or nemover_din a mone —G_inount_» the US8_falr system can.r attached te the hot file-sy an) a 7 Scanned with CamScanner 2.4 SYSTEM CALLS a way by which user program request for services from the kemel, provide an interface to the services made available by an system. Step by step explanation of system call mechansim: * A process running a user program in user mode want to execute read tion a file. it has to execute a trap instruction to transfer control operating system. 12 Scanned with CamScanner + System call read has three parameter : the first one specifying the file, the second one pointing to the buffer, and the third one giving the number of bytes to read J count = read(fd, buffer, nbytes): J+ the aameters are first pushed onto stack. + library procedure are called in the step 4 «The library procedure, possibly written puts the system- call number ina pl expects it, stich as a register (step 5) lace where the operating system + Then it executes a TRAP instruction to switch from user mode to kernel mode and start execution at a fixed address: wi step 6). y hin the kernel + The kemel code that st arts following the TRAP examines the system- call number and then dispatches to the correct system-call handler, usually via a table of pointers to system-call handlers indexed on system-call number (step 7). + At that point the system-call handler runs (step 8). + Once it has completed its work, control may be retumed to the user- space library procedure at the instruction following the TRAP struction (step 9). + 12, This procedure then returns to the user program in the usual way procedure calls return (step 10). Retum 1 calor (| Ubrary § procedure, q { waa Z ; aH : ° aoe a er | tetas J 7 4 mere | 2 pars roredsten | | [eens PES] Ses | Figure 2.1 system call for read Reference: Modern Operating system, Fourth edition, Andrew. S. Tanenbaum, Herbert Bos 2 1 System calls for Process management: A system to create a new process or a duplicate process is fork 13 Scanned with CamScanner 2.4.2 System calls for File management: will have all date in the file description and Je process rhe duplie ors COMMON. nx parent process and the duplicate ig, we The original process ix known dl as the child process The fork call returns a value, W hich is zero in the child and equal to the child's PID (Process: {WDentifier) in the parent sit would request the services for terminating a Known system calls The process of the original image with duplicate Loading of program or-changing execution of exec needs Pid would help to distinguish between child tem calls in Linux from parent process and parent process a of Process man: a duplicate pro supposed to wait for other processes to complete wait their work exec: loads the selected program into the memory erminates the process A file is open using a system call open. The mode in which the file is supposed to be open is specified using consist of the names of the file to open the parameter, Parameters or a new one to be created. The files are closed using the close systems. Associated with each file is a pointer that indicates the current position | in the file. When reading (writing) sequentially, it normally points to the next byte to be read (writen). The Iseek call changes the value of the position pointer, so that subsequent calls to read or write can begin anywhere in the file. Lseck has three parameters: the first is the file descriptor for the file, | the second is a file position, and the third tells whether the file position is relative to the beginning of the file, the current position, or the end of the file. Eg of systems calls for file management open: for opening the file for reading, writing close: to close the opened file read: for reading the data from the file into buffer write: for writing the data from the buffer into file Scanned with CamScanner 2.4.3 System calls for Directory management: mkdir is a system call that creates and emply directories, whereas imdir removes an empty directories. link allows the same file to appear under two or more names, often in different directories for allowing several members of the same programming team to share a common file, with each of them having the file appear in his own directory, possibly under different names. By executing the mount system call, the USB file system can be atiached to the root file system The mount call makes it possible (o integrate removable media into a single integrated file hierarchy, without having to worry about which device a file is on 2.4.8 Windows Win32 APL: + Window's program are event driven, An event oceurs that calls the procedure 10 handle it. Windows functioning is most driven by GUI ‘yased interactions like mouse movement, There are system calls which are exclusively present windows to deal with GUT and many of the ystems calls which are present in UNIX are missing [Link] 2 some of it: + CreateProcess: Creates a new process in Win32 itForSingleObject: Waits for a process to exit + ExitProcess: Terminates the execution of process CreateFile: Opens an existing file or creates a new one SE e. —— 2.5 OPERATING SYSTEM. 2.5.1 Monolithic Syste + In the monolithic approach the entire op‘ program in kernel mode +The operating system is written as a collection of procedures, linked together into a single large executable program. + Each procedure in the system is free to call any other process call any procedure makes the-system very efficient 1g —every procedure is visible to every other erating system runs as a single + Being able to + No information hidin procedure + Eg. MS DOS and LINUX nization suggests a basic structure for the operating system: + This orga Main Function- invokes requested service procedure + Service Procedures- carry out system calls Utility functions- Help service procedures to perform certain USNS 15 _ Scanned with CamScanner Disadvantage: + Difficult and complicated structure : : ‘A crash in any of these procedures will take down the entire operating ” system Figure 2.2 Monolithic Structure Reference: Modern Operating system, Fourth edition, Andrew S._ Tanenbaum, Herbert Bos 2.5.2 Layered System: Layer Function The operator User programs Input/output management Operator-process communication Memory and drum management Processor allocation and multiprogramming Figure 2.2. Layered Struture Reference: Modern Operating system, Fourth edition, Andrew §._ Tanenbaum, Herbert Bos S]+!mlwolala + The operating system is organized as a hierarchy of layers, each one» constructed upon the one below it. The first system constructed in this way was the THE system. The same concept of layered approach was. also implemented by MULTICS with concentric rings, The procedures 16 Scanned with CamScanner in out rings are sup, Posed to make a system call to access the process in the inner ring + The diagram reflects the structure of The operating system with following details : Layer 0 dealt with allocation of the processor, switching between Processes when interrupts occurred or timers expired. Layer | did the memory management, It allocated space for processes in main memory. + Layer? handled communication betw: consolea + Layer 3 took care of managing the /O devices and buffering the information streamso Layer 4 was where the user programs were found. Layer 5 : The system operator process was located, TRAP instruction whose parameters were carefully checked for validity before the call was allowed to proceed. : Microkernels: = qn User programs User mods < Servers: Drivers NGS emesacistses eSies ieee estes io + Microkernel structure focusses on making the keel smaller by reducing the non essential components from the kernel. These non essential components are placed in user space. + The basic idea behind the microkemel design is to achieve high reliability by splitting the operating system up into small, well-defined modules. + the microkerne!—runs in kernel mode. The main function of microkemel is to provide a communication facility between the client program and various services that are also running in user space 7 So % tt seep eee Scanned with CamScanner 2.5.4 Client Server System: 2.5.5 Exokernel: se) Kemal All new setvices are added to the user space and the kernel don’t nee to be modified. Microkernel provides high security and reliability as most of th services are running in user space , if a service fails the rest operating system remains untouched. Disadvantage + Performance decrease due to increased system function overhead Machine 1 Machine 2 Machine 3 Machine 4 Cleat Fll server Process server Terminal server Kernel Kemal 1 | ‘Massage trom alent fo saver ‘The servers, each of which provides some service, and the clients, which use these services. This model is known as the client-server. model, Since clients communicate with servers by sending messages, the clients need not know whether the messages are handled locally on their own machines, or whether they are sent across a network to servers on a remote machine. As far as the client is concemed,: requests are sent and replies come back. ‘Thus the client-server model is an abstraction that can be used for a # single machine or for a network of machines Exokemnel runs in the bottom layer of kemel mode. Its job is to allocate resources to virtual machines and then check attempts to use them to make sure no machine is trying to use® somebody else’s resources. 3 The advantage of the exokemel scheme is th, mapping whereas the virtual machine monitor remap disk addresses at it saves a layer of must maintain tables to The exokernel need only to keep track of which virtual machine has been assigned which resource Scanned with CamScanner : — : ace Treen) Program tn execution An Instance. of manning 8 preg LO & preg.” Veeck Tally : —_ Procen _{Idhem in MH call brecess — ‘egal —ef prs cine —ingice H IM Scanned with CamScanner —-Mattonal, Zig A 6.) Ty hong Team Schedudere. Coo by Resd) 7s 2 Shop _(Reacl te Running | _ 2 Preemtve. — Thread» igi he a cali sic unit of fe “eatultoin or CPL UU shan) - $f _trinprigia of A thuesd rp, PC Rew ten Stack : GE Shas cocks, data L Cthe, teroubeese ———— = —hdenginy arnt brouns ———— —_ 2h teaditi gabe o bgt —frecens hes o_sing ht thazad. of con*ac lk 2-Lf 1 procens hos Se —cte_pokform more thanem _tark Scanned with CamScanner > Renponsiverwss - > Resource sharing, a > bi eee = > Vile etien sane a Aa @ 95 treat differcal Protea» AMD Ue Se LO Se = task for O5 © Differemt pro Thieads phon Adone cobs a iets a O Corteah_wottching tb slower Context switching ¥» facta, . d TH Bloking a broctas wilh Blocking a thre wilt mot Bock arother. Block Gentine. proces Gy Trdkbendent ‘Intex del onal oa: Scanned with CamScanner 0 a by “Von live i (npp- Ae yg * Cielo ay ci vv tovel vende On. “pally aT ‘Slovien | Bfonukeaned. | = =e tl. tacadl | aaa gt sac Pane eer caver blocked jet Sauer gies Pb o-mechomtsmn that olltos | Steen tLe Communteal. voit [Link], Cund. Sipnthwonize thes, — _Ockto ho. eng data_bf Bio ann ith_eath other tough Scanned with CamScanner Communt colton mm Uient [Server Axchi becturr 8 Pee. —— + Sockel —_ + Romoti Procedural alba (8 PCs) ——— et ¢g —dusae._pe — tS Fe paing com —fo2. st . dg sol ata, — mere ryG buffer, — bods, ea 4 TReTC, vlobbp _ ar Barone ane ae pests —ydhnaniad, tom ioe he Scanned with CamScanner Bounded " Ie a (Producer tonatnen) _ a lele slelele : sem _ minis] alee bele lg fe, | mune : Share, bute wt ot (out Re, Pate wilh ts (toe t z- Produces 4 abou donot trtetact ote whe), duces Ketbs on fe foat) co fonacimnen ~ Corsumer emphy a then. ~ Sets Scanned with CamScanner TH GY ond, dat fpr #7 5 ig i CH Hr cakire 4ipr taking Winking YX ne Hem ee ang) (Hungry prot) ee ST Sb ke huey fr 2 atene 50! CP, fin Hy Tarek wth a Eke Scanned with CamScanner ivy - amchomisin. Js_am.object = cor: Fos tang List of “Ps nti me jae Gare Gee faleare tT a tock b= =a ae Scanned with CamScanner Cho, Schecduulin (Seleetng a hroetoe re Susu AM }- : q q : The poset of OS hel makes chotee, fs called Schedules.) 6 the alga Ab uso ts called, Scheduling slgo ( a Cpu Schedutbing hy done ts achieve. d > Max (PU ubtlizatfon > Max TAy Min Recbomse Time 3 Min ee Time. me Mx ane a eee aa aT CFU bowel To oun Scanned with CamScanner reer eee eee eee eee eee eee tte ete National Wei ot of bine) ial Arvctvel Time <> The dime at which process onto dhe, Ready Quene — (hom enter) west Time > Time Mequixed, 'y a fret to qe A exeeshy 2. (Duration) = C15 amine Nima) | Sempletfon Time > The fine, Of tohich, proces Complds. ths erecubian. | ae C2. pm pal) vind, ime TCompllon, Thaw, = Readvol, Time) hr Gorin) Watling Time > [TAT - Burst Time}, - CGomin — Simin = 'Srain) Te_fis wtf procer go et CPD ~ Arcrived Tims t bint of Hr) : i L& Fs_(Btist Co ma Spf tortie aw opel Non= Prueinblive ta aehals fb Mbt Ophiinol AIT, hoo CfU 2 dion, Connot whilire resource, i fe tual _Arvival Bust c TAT RT Time jm T ~ Scanned with CamScanner (Shortest ob Tisat’) Gettota Burst Time Mole ! Non Patumphie ) —@__SRIF ee p+ Exduradons of STE ([Prcesinpie) -—____Odilesja, — BT, Mode = Peete _ Provan Wo. BT BT f, 0 5 eh I 3. Le 2 | f, a | Scanned with CamScanner | ', Ir fos fr Je fn Sa 5 6 ft ot 2 oy 2 fP. Cenmfoar leo oof hued dime fh a hw) ) ce eee j—ffs [conflict cox both hove same 01 Ahan thal tere AT) | Pars fog TaT= 94344) ay 6 cis { Aug, WT Ktoryio | Pe gas _ 4 a Ceawattor- - frove Seon )_Biinsiy Sehe Lig te! _ — xy buteta Ray No ole, — — Prasmplve. |__ > Won= Putemphive | —!stosity NG == fee ae ee TAL WT Scanned with CamScanner ~ ©. Round Robin Adal - = Dui pe spel fo iw at ape ss = Gains ha en Fe hfe. turing Baus ‘ae et eet of ine TT =o a eerie | Scanned with CamScanner Mallepte kevel. Quccurs Scheduling - r oR Sq stew Proceas ~Hntexartive Rrocess I oe |. Batch —Proceas— FCT —_—_——— Acenasi. OO Malitladt feedbock Queut wlullklal feedhock Gusus ape mS if Completed eat am, 1 ake if ompered cok : J eae neo Ta: Semi ny all fers manner = Kech how ing fe quieut_of_honte prioatty procs, — Sa thak ww — st akin! f t : eo tH ghest po Scanned with CamScanner 3.2PROCES, aS — + Definition : Process is a program in execution + A running process are organized into sequential processes. Every process needs CPU for completing its execution. CPU switches back and forth between these running processes + In any multiprogramming system, the CPU switches from process to process quickly, running each for tens or hundreds of milliseconds + A process is an activity of some kind. It has a program, input, output, and a state. o A single processor may be shared among several processes, with some scheduling algorithm being accustomed to determine when to stop work on one process and service a different one. In contrast, a program is something that may be stored on disk, not doing anythingProcessmemory is divided into four sections: + The text section comprises the compiled program code, read in from non-volatile storage when the program is launched. + The data section stores global and static variables, allocated and initialized prior to executing main. The heap is used for dynamic memory allocation, and is managed via calls to new, delete, malloc, free, etc. * The stack is used for local variables Scanned with CamScanner 3.21 Process Creation: esses to be created: Vour principle events cause processes 0 1. System initialization: s processes are created. When an operating system is hooted, numerous pro reated. * Sime of these are foreground processes: processes that interact wit {hnman) users and perform work for them. so ca as \e1 fi + Others run in the background also calles. da ato ad cr associated with particular users, but instea s Pecif function 2. Execution of a process-creation system call by a running process, \ running process will issue system calls to create one or more processes to help it do its job 3. A user request to create a new process: * A new process is created by having an existing process exec ute, Process creation system’ call In UNIX, system call to create a new process: fork() In Windows, CreateProcess(), with 10 parameters handles both proc creation and loading the correct program into the new process, 4. Initiation of a batch job: Users can submit batch jobs to the system. When the operating system creates a new process and tuns the next joy from the input queue in it 3.2.2 Process Termination; Pe of error occurs i ilegalinstuetion, referencing” PTO8TAM bug like executing a + 3on-existemt memory or dividing by zero, Fatal exit A termination of a process occurs When it disco EN * For example, Vers a fatal error. : if user types ‘the command: Scanned with CamScanner sce xy + to compile the program xyz.c and if no such file exists, the compiler simply announces this fact and exits. Killed by another process: \ process evectites a system call fo kill some other process In UNIN this call is called as kill, The corresponding Win32 function is YerminateProcess terminated admitted interrupt scheduler dispatch \/0 or event completion’ VO or event wait Figure 3.1 Reference: “Operating System Concepts” by Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin Process model makes it easier to understand what is going on inside the system. Some of the processes run programs that carry out commands typed in by a user other processes are part of the system processes. When a disk interrupt occurs, the system makes a decision to stop running the current process and run the disk process, which was blocked ‘ing for that interrupt. Any process in the system is present in any one of the given states New — The process is in the stage of being created. Ready — The process has all the resources available that it needs to run, but the CPU is not currently working on this process’s instructions. Running - The CPU is working on this process’s instructions. Waiting — The process cannot run at the moment, because it is waiting for some resource to become available or for some event to occur, For example the process may be waiting for keyboard input, disk access request, inter-process messages, a timer to go off, or a child process to Finish, Terminated — The process has completed, Scanned with CamScanner * In addition to these resources, a process has a thread of control, e.g, + The idea of threads is to permit multiple threads of control to execute ~ 3.3.3 Implementing thread in User Space: + Thread has an ability io share an address space and all of its + Threads are lighter weight than processes. they are faster to create ai 3.3.2 Classical Thread Model: + A process contains a number of resources such as address space, ope 3.3 THREAD 3.3.1 Thread Usage: i unit of CPU utilization, consisting of a progra + A thread isa b counter, a stack. + A process have a single thread of control ~ There is one prog counter, and one sequence of instructions that can be carried out at au ind a set of registers. given time + Decomposing an application into multiple sequential threads that in quasi-parailel, the programming model becomes simpler among themselves. This ability is essential for certain applications. destroy than processes. 1 a : q files, accounting information, etc. program counter, register contents, stack. within one process. Individual threads within the same process are not completely independent but are cooperating and all are from the same process. The shared resources makes it easier between threads to use each ot resources. A new thread in the same process is created by a Ii ine Ii nth y a library routine Jil thread_create; similarly thread_exit terminatea a thread. : Sa The entire thread package is kept in the usi eee er space and kernel has no. Kernel manages ordinary and single threaded Processes ‘The threads run on top of a run-time system. Run time system is a collection of Procedures that manage threads, e.g. pthread create, pthread exit, pthread join, and pthread yield, Each process needs to have its own private thread of the threads in that process. Table 10 keep ir Scanned with CamScanner ick of each threads propertics «+ The thread table keeps «Thread tables are managed by runtime system Advantages: Can be implemente gre implemented by library 4ton the OS that do not support thread and thread Requires no modification in the operating system 11 gives better performance ay there is m0 context switching involved from kernel Fach process is. allowed 10 have its own customized scheduling algorithm. Disadva + tinplementing blocking system calls would cause al thread to stop. 1f-a thread starts running, no other thread would be able to run unless xe thread voluntarily leaves the CPU. Process Thread User space Kernel space Run-time Thread Process system table table Figure 3.2 3.3.4 Implementing thread in User Kernel: + Kemel manages the thread by keeping ‘a track of all threads by maintaining a thread table in the system. + When a thread wants to create a new thread or destroy an existing thread, it makes a kernel call, which then does the creation or destruction by updating the kernel thread table. . ae kernel’s oe table holds each thread’s registers, state, and other information and also maintains the traditional proces’ ‘a cess table ec] track of processes c eae Advantages: Thread-create and friends are now systems and hence much slower. Scanned with CamScanner in Tul that blocks causes no particular problem. The kernel can run .s or can run another process. ead does not automatically block the A thread another thread from this proces Similarly a page fault in one th other threads in the process. Disadvantages: 3. ter cost of creating and destroying threads in the kernel hich thread should handle it is a en a signal comes in then w problem Process Thread Process pate fain Figure 3.4 5 Hybrid implementation: Hybrid implementation combines the advantages of userlevel threads with kernel-level threads. One way is use kernel-level threads and then multiplex user-level threads onto some or all of them. This model provides maximum flexibility The kernel is aware of only the kernel-level threads and schedules those. These user-level threads are created, destroyed, and scheduled like the user-level threads in a process that runs on an operating system without multithreading capability Multiple user threads on a kernel thread space = _kemel tnread / Scanned with CamScanner Race Comdthon A veate Condihion ~petuha when aN a procens¢s access L. mmeunipwlate Hu som loka Conettucembly £ @ ubcome Sf ereenthon olehemds on Re hor htulor orcleu tr. colic Ake Jocetns Aakers ploce a Sy af, fae Memory | a ? - = offste e p. Read K 40 Read ES lo y Keio Aefi K=X+10 2o Py a at of rg tohere the Shared \ Hl Fi Bidoouern Ps Accemea U CS al Kot Heal, Section >. aa yp 05 shone eA) cade waged enka + process eer execs OO ime Hora np ___ 67 Ut bo a CQ bine proces sword deadlock. dy Woued ato ereguh in Cs), rol | | Scanned with CamScanner 3.4 INTERPROC COMMUNICATION chanism that allows the exchange of data between processes ween the processes without and data sharing + How one process can pass information to another? cond has to do with making sure two or more processes do not hh other’s way. hind concems proper sequencing when dependencies are present. 3.4.1 Race Condition: ; In 1g m processes that are working together may share ome common storage that each one can read and write. ared storage may be in main memory. 's access and manipulates shared data simultaneously. S everal proce 4, Final value of shared data depends upon which process finishes last. Fig. shows ; Multiple user threads ona kernel thread User space ; Kernel —— Kernel thread space Figure 3.5 1. In the above example, file name is entered in the special spooler directory for printing nv he Printer daemon prints the files and then removes their names from the directory. Imagine 7 Our spooler directory has a very large number of slots, ered 0, 1,2, ..., each one capable of holding a file name, Scanned with CamScanner 4. two shared variables, in variable pointing to next free slot ©. out variable pointing to next file to be printed. Process A reads in and stores the value, 7, next free slot. Just they ck interrupt occurs and the CPU decides that process Switches process B 8. Process B also reads in and gets a 7 in local variable next free slot. °. Process B now continues to run. It stores the name of its file in s} and Then it goes off and does other things. - Eventually. process A runs again, starting from the place it left off. - Tt looks at next free slot; finds a7 there, and writes its file name in - erasing the name that process B just put there. 3.4.2 Critical Region: Definition: Part of the program where the shared memory is accessed | called the critical region or critical section Race condition can be avoided by ensuring that no two processes are evi in their critical regions at the same time. Following four conditions needed to have a good solution: 1. No two processes may be simultaneously inside their critical region 2. No assumptions may be-made about speeds or the number of CPUs. 3. No process running outside its critical region may block any s. 4. No process should have to wait forever to enter its critic Scanned with CamScanner A441 Producer Consumer Problem (Bounded Buffer): spadteer- consumer problem also known as bounded buffer Yolen which assumes that there isa fixed sized buffer available, © Jo suspend the producers when the buffer is full, to. suspend the consumers when the butter is empty, and to make sure that only one process at a time manipulates a butler so there are no race conditions, share a common, fixed-size (bounded) buffer. The producer puts information into the buffer and the consumer takes information out, + Two processes + Problem arises if the following scenario comes across: + The producer wants to put a new data in the buffer, but buffer is already full. Scanned with CamScanner 4410 be awakened when the cons sleep ane jo remove data from the buffer Solution: Producer goes 10 Solution: Producer § mer wal has removed data. The const butfer is already emply to sleep until the producer Puts some dag g Consumer goes 10 / Solutio a a buffer and wakes consumer HY Conclusion: ads to same race conditions We have seg, Jition can occur due to the fact that access he problem is that a wakeup g This approaches also cont carter approaeties, Rave 69 count’ is uneonstrained. The ae ec] 9, isl sent to a process that is not sleeping, is lo essence of | 3.4.5 Semaphore: E,W. Dijkstra (1965) suggest semaphore, an integer variable count the number of wakeups saved for future use. A semaphore cogj have the value 0, indicating that no wakeups were saved, or some posi value if one or more wakeups were pending. Two operations are performed on semaphores called down(sleep) and up(wakeup). Processes to synchronize their activities, ‘These operations are also known as: wait() denoted by P and signal() jx denoted by V. wait(S) { while (S <= 0) s } signal(S) (Ses; } 3.4.6 Mutex: Mutex is a simplified version of mani 2 the semaphore u: m mutual exclusion of shared resour : 2 " rces, + They are easy and effici : ent to implement that are implemented en o tirely in user space, * A mutex is a shared variable 1 i Mei i hat can be in one of two states: unloc! d useful in thread pack: 10 use a on the semaphore, When a Prov signal() operation, Scanned with CamScanner 5.6. Dinning Philosophers problem: sophers sit ata round table with bowls of spagheuj, losopher must alternately think and eat. Scanned with CamScanner cat spaghetti when he has both left held by only ane philosopher and 90 is not being used hy another a philosopher ean only Hach fork can be use the fork only if i However, snd Hight lor philosopher philosopher Afier he finishes eating, he needs to put down both forks wo th available to others. becom right or the one on his left an take the fork on his before getting both of ailable, but cannot start eating \ philosoph they became them: The problem is how to design @ discipline of behaviour (a concurrent algorithm) stich that no philosopher will starve. is the basic idea of the problem: the dining Mutual exclusion scenario useful for create a generic and abstract issues of this type. ‘the failures these philosophers may experience are analogous to the difficulties that arise in real computer programming when multiple programs need exchisive access to shared resources Problem: fers from the problem of deadlock when neously. If all five philosophers take their e will be able to take their right forks. and Dinning philosopher su everyone want to eat simultai left forks simultaneously. Non there will be a deadlock. The second problem of starvation arises when the philosophers could start the algorithm simultaneously. picking up their left forks, seeing that their right forks were not available, putting down their left forks, waiting, picking up their left forks again simultaneously, and so on, forever. : Figure 3.6 Dinning Philosopher Problem: Scanned with CamScanner 3.6.2 Readers and Writers problem: rs problem is useful for modelling to a limited number of SSes Tesoy, *ees, The dining philosophe! for exclusive access a are competi sh as VO devices There is a data area that is shared among a number of Processes, r of readers may simultaneously write to the data write to the data area. atea, * Any numbe: Only one writer at a time may If a writer is writing to the data area. no reader may read it. If there is at least one reader reading the data area, no writer May write to it, Readers only read and writers only write. The Reader and Writer problem, which models access to a database, For example, an airline reservation system, with many competing processes wishing to read and write it. It is acceptable to have multiple processes reading the database at the same time, but if one process is updating the database, no other process should access the database, not even readers. To avoid this situation, the program could be written slightly differently: when areader arrives and a writer is waiting, the reader is suspended behind the writer instead of being admitted immediately, Scanned with CamScanner SHEDULING tof the ope ting system that makes the choice is called the and the algorithm it uses is called the scheduling algorithm py ler 4 Processes ave of OVO types Compute bound or Input output, bound Compnte-bound processes have long CPU bursts and infrequent VO Qvaits VO-bound processes have short CPU bursts and frequent VO waits bof the CPU burst is an important factor 1a disk © I takes the same time to issue the hardware request to te block no matter how much or how little time it takes to pros er they artive. Scheduling is of two types preemptive and non cmptive ‘ified as Batch, Interactive and Real ling Time place when one of the following condition is rom the running state to waiting state + CPU scheduling take witching of proce + Switching of process from the running state to ready state Switching of process from the waiting state to ready state When a_ proc terminates + scheduling under conditions 1 and 4 is, called as non-preemptive scheduling. scheduling under conditions 2 and 3 is preemptive scheduling 1 First Come First Serve(Fefs): + It is a non preemtive algorithm where the ready queue is FIFO procedure. + Processes are assigned to the CPU in the order they requested it. + The strength of FCFS algorithm is that it is easy to understand and equally easy to program. + Ithas a major disadvantage of high amount of waiting time + Ttalso suffers from convoy effect where in many small process have to wait for a longer process to release CPU. | Process | Burst | Arrival | Start Wait Finish TA | | Time_| ia [24 0 0 0 24 u4 (2 3 0 24 ay 27. 27 : 13 0 7 27 30 [30 Scanned with CamScanner aii Gantt chart: 042442793 = 17 average waiting time! O30) = average turnaround tiie: 3.5.2 Shortest Job First(SJF) sociated the Iength of its next CPU burst. ach process is as 3 + According to the algorithm the scheduler selects the process with shortest time SIF is of two tyPES process once 1U burst time preem scheduled will continue running: iptive also known as shot RIN): A process preempt if a new proces f less length than the remaining time of the F is an optimal algorithm which gi for any set of processes but suff ‘he run times are known in advance. + non-preemptive: A until the end of its CPI remaining time next(S arrives with a CPU burst 0 currently executing process. Ss minimum average waiting time from the drawback of assuming t SIF (Non Preemptive) Process | Burst | Arrival [ Start [ Wait | Finish Time 1 6 0 3 3 9 2 8 0 16 16 24 3 7 0 9 9 16 4 3 0 0 0 3 Gantt chart: Py P. 1 Pg Pp 0 3 8 16 average waiting time: (3+1649+0)/4 =7 average turnaround time: (9+24+16+3). Process | Burst Time | Arrival Start > 1 8 0 Wait _| Fini 7 4 ; 0 9 iaish TA 3 9 3 1 0 17 4 3 3 17 [ 31S 2 4 average waiting time; (9+0+15+2)/4 3 6 2 10 24 average turnaround time: (174442, eine: 3 7 Scanned with CamScanner 3.5.3 Priority Scheduling: Prionty schedulin, it ieduling associate: its PCB block - T 3 priority number with each process in he runnable process, : Pp with the highest priority is assigned to the CPU y is assig J hoof 2 processes y e 7 with the same priority is handled using FCES i to take exter fact external factors into account leads to priority prevent high-prio : ler may a Processes from running indefinitely, the ier may ase the priori : . : a clock tick Priority of the currently running process at sities can be assigned to proc ses statically or dynamically 0 me —e with starvation low priority processes may never may have to wait indefinitely for the CPU therefore as a ion ageing is attached with each Process Burst Priority | Arrival | Start | Wait Finish | TA Time Number | | 7 10 3 o | 6 | 6 16 16 2 7 1 Lo | o-} 0 1 1 3 2 4 OA EGG 18 18 4 i 5 o | is | 18 197 |a19) 3 5 2 oe 6 | 6 —— Pe Py o 1 6 16 18 19 average waiting time: (6+0+16+18+1)/5 = 8.2 average turnaround time: (16+1+18+19+6)/4 = 12 3.5.4 Round Robin Scheduling(RR): = Round Robin scheduling algorithm has be time sharing system + Time pre-emption of process would take place. + The ready queue is bi access in circular manner + The RR scheduling algorithm is processes in the ready queue and 1 process gets 1/n of the CPU time in thus preemptive. If he time quantum is + Each process mus! next time quantum. «The selection of time slice (q) plays an important role. quantum or time slice is a small unit of time defined a t wait no longer than (n 1) x 4 time unil .en designed specifically for ifter which ased on FIFO order with each process getting there are 1 g, then each hunks of at most q time units. its until its Scanned with CamScanner Round R if q is very large. il result into loo if qis very small, it wt the overhead time obin behaves like FCFS many context switch leading. 8b Process) Burst. | Arrival | Start. | Wait | Finish | Time | | cee eee eEEEEECE| \ ‘24 | 0 0. 6 30 (30 2 3 0 | 13 {oO 10 quantum = 4 Gantt chart: Py | Pa | Pa |. PA Py | |» | 0 4 7 10 14 18 22 2. Average Waiting Time: (6+4+7)/3= 5.67 Average Turn around Time: (30+7+10) = 15.67 Scanned with CamScanner

You might also like