0% found this document useful (0 votes)
17 views33 pages

Operating System MQ

Operating system MQ

Uploaded by

runjhunsingh809
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)
17 views33 pages

Operating System MQ

Operating system MQ

Uploaded by

runjhunsingh809
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
‘+ The medium term scheduling affects processes + ready-suspended « block-suspended + The long term scheduling affects processes Long Term Scheduling : Long term scheduling controls the degree of multiprogramming in multitasking systems, following certain policies to decide whether the system can honor a new job submission or, if more than one job is submitted, which of them should be selected, ‘The need for some form of compromise between degree of multiprogramming and throughput seems evident, especially when one considers interactive systems. The: higher the number of processes, the smaller the time each of them may control CPU for, if a fair share of ‘responsiveness isto be given tall processes. Avery high number of processes causes waste of CPU time for system housekeeping chores. However, the number of active processes should be high enough to keep the CPU busy servicing the payload (Le. the user processes) as iiuch as possible, by ensuring that-on average-there always be a sufficient number of processes not waiting for VO. Medium Term Scheduling : Medium term lly concerned wi Short Term Scheduling: Short term scheduling Concems with the allocation of CPU time to processes is order to meet some predefined system performance objectives. The definition ofthese obj it policy) i an overall system design issue, and determines ‘environment. The two most common kinds of semaphores are counting semaphores and binary semaphores. Counting semaphores represent multiple resources, while binary semaphores, athe name implies, represents two posibe States (generally Or 1; locked or unlocked) ‘A semaphore can only be accessed using the folowing operations: walt) andsignal( wait) called when reer wa tices a resus if the Semaphore is pester than , then can thatrerurce Fite senapheee Sona coos isn’t available, that process must wait until t becomes tvailable. signal( sealed when a proces is done asing f resource Yes, semaphores can be used to solve the reader ter problem withthe following implementation Conditions: j 1. No reader wl be kept w the abject. 2. Writing is performed ASAP precedence over readers, ‘The reader proceses share the semaphores mutex tnd wrt and the integer readcount. The semaphore were, Also shared with the writer processes Mutex and wrt are each initialized to 1, and ing unless a writer has . writers have readcount is wait(wrt); wait(mutex); readcount = readcount + 1; ifreadcount = 1 then wait(wrt), ignal(mutex), ‘reading is performed*/ ‘wait(mutex); readcount := readcount- 1; if readcount = 0 then signal(wnty, Signal(mutex); ‘Ans. Solutions to the Critical Problem Solution tothe Critical Section Probless three conditions : ne 1. Mutual exclusion : “Grifical Section, no other, (9.12) 4. Progress : If no process is éxecuting in its critical section and there exists some processes that wish to enter their critical sections, then only those processes that are not executing in their remainder section can participate in the decision, of which will enter its critical section next, and this decision cannot be postponed indefinitely (a) If no process is in critical section, can decide quickly who enters (b) Only one process can enter the critical section so in practice, others are put on the queue 3. Bounded waiting : There must exist a bound on the number of times, that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted (a) The wait is the time from when a process makes a request to enter its critical section until that request is granted : (b) In practice, once a process enters its critical section, it does not get another turn until a waiting process gets a turn (managed as a queue) aa (i) Running: Once the process has been assigned {04 processor by the OS scheduler, the process states st to running and the processor executes its instructions (fv) Waiting: Process moves into the waiting state ifitmeed to wait for a resource, such as waiting {or user input, oF waiting for a file to become available. (%) Terminated or Exit: Once the process finishes itsexecution, otis terminated by the operating stem. itis moved to the terminated state where it waits tobe removed from main memory. Processes mtching is context switching from one sir arss {0 different process. It involves switching out all of the process abstractions and Fesources in favor of those belonging to a new process, Most notably and expensively, this means in mory addresses, Fesources, a relati ‘mappings, page ively expensive ead switching is about ind exiting the kemel ing is significantly faster Cost of entering ar thread switch 4 °A thread is a single sequential on mee ne Af Prograrimers are familiar with writing Sequential srograms. You have probably written « Program that displays or sorts alist of names, or Commputes a list of are sequen 4 beginning, an end, a during the runtime of the program there is a single point f execution. : orem thread is similar to a sequential program a single thread also has a beginning, an end, a sequence, and at iny given ime during the runtime ofthe program, there i ‘single point of execution. However, a thread itself is not @ program, it cannot run on its own, but runs within a program, A thread is a basic unit of CPU utilization; it Comprises a thread ID, a program counter, a register set, and a stack. It shares with other threads belonging to the Same Process its code section, data section, and other ean system resources, such as open files and signals. A traditional process has a single tistead Of control. If a rrone thats Multiple threads of control, it can perform ‘more than 1 task at a time, ‘Threads are visible o: nly from within the process, ‘where they share all process resources i ike address space, Chen files, and so on. The following state is ‘unique to each thread, + Thread 1D {_ Resister state (including PC and stack Pointer) + Stack . al mask Priority * Thread-private storage Kernel Level Threads : Kemel threads are yipported and managed directly by the operatin tually all contemp system, orary operating systems including indows XP, Linux, Mac OS X, Soler ‘and Tru64UNIX Support kemel threads, Bieta) Q ern Leet Thea Fig: Kerntlevel threats Advantages” “Advantages ss having large number of threads than proces having small number of threads + Kemel-level threads are especially good for applications that frequently block. Disadvantages + Thekemel-level threads are slow and inefficient. For instance, threads operations are hundreds times slower than that of user-level threads, * Since kemel must manage and schedule threads as well as processes. It require a full thread control block (TCB) for each thread to maintain information about threads. As a result there is significant overhead and increased in kernel ‘complexity User level threads : In this method, the kernel knows about and manages the threads. No runtime system is needed inthis case. Instead of thread table in each process, ‘the kernel has a thread table that keeps track of all threads, in the system. In addition, the kernel-also maintains the traditional process table to keep track of processes, Operating System kernel provides system call to create and manage threads. User threads are supported above the kernel and managed directly by the operating system, User-level threads implement in user-level libraries, rather than via systems calls, so thread switching does not need to call operating system and to cause interrupt to the kernel. In fact, the kernel knows nothing about user-level threads and manages them as if they were single-threaded. Processes. : }ustocrmeed re. 1 User level threads ‘The most obvious advantage of this technique is that ‘user-level threads package can be implemented on an Operating System that does not ‘support threads, User-level threads do riot require modification to operating systems. Simple Represeni + Each thread is imply by a PC, registers, stack and a small control block, all stored in the user process address space. + Simple Management : This simply means that creating a thread, switching between threads and synchronization between threads can all be done without intervention of the kernel. + Fastand Efficient : Thread switching is not much more expensive than a procedure call Disadvantages + There is a lack of coordination between threads and ‘operating system kernel. Therefore, process as whole gets one time slice irrespective of whether process has one thread or 1000 threads within. It is up to each thread to relinquish control to other threads. User-level threads require non-blocking systems call i.¢.,a multithreaded kernel. Otherwise, entire process will blocked in the kernel, even if there are runnable threads left in the processes. For example, if one thread causes a page fault, the process blocks. QU3 What are the five major activities of an operating system with regard to file management? [Link]. 2016] ime ERE Ans. Five major activities of an operating system with regard to file management ar 1. Creating and Deleting Files: File creation and deletion are fundamental to computer operations In the former, data cannot be stored in an efficient manner unless arranged in some form of file structure. In the latter, permanent storage would quickly fill up if files were not deleted and the space ‘occupied by them reallocated to new files, Crenting and Deleting Directories: As a Corollary to the need to store data in files, files themselves need to be arranged in director, folders in order to allow their efficient storage and retrieval. Much like file deletion, unnecessary directories or folders need to be removed in order to keep the system uncluttered, File Manipulation Instructions: Since operating systems allow application software to perform file manipulation using symbolic instructions, the Operating system itself needs to have a machine. level instruction set in order to interface with the hardware direetly. The application's symbolic instructions need to be translated into the machine. level instructions either by an interpreter or by compiling the application code. The operating system contains provi ons to manage thi: _ level file manipulation, a es or ‘0 Permanent Storage: Operating 7 aes ‘need to be able to map files and folders to their physical locato’ on permanent storage in order to be able to store and retrieve them. This will be recorded in some form of disk directory, which ‘Varies aocording to the file system, or systems that the operating system uses. The operating system clude a mechanism to locate the separate file segments where ithas divided a file. 5. Backing up Files: Eiles represent a considerable investment in time, intellectual effort and often money as well, thus their loss can have a severe impact, Computer's permanent storage devices generally contain a number of mechanical devices, Which can fail, and the storage media itself may degrade, A function of operating systems is to obviate the risk of data loss by backing files up on additional secure and stable media in a redundant system. Z & Whar are the two. models of interprocess ‘communication? What are the strengths and weakness of the two approaches? —[[Link], 2016] ‘Ans. Two Models of Interprocess Communication : ‘There are two interprocess communication models given below: 1, Message-passing Model : In this; the communicating processes exchange messages with one another to transfer information. Messages can be exchanged between the processes either directly or indirectly through @ common mailbox. Message passing is useful for exchanging smaller amounts of data, because no conflicts need be avoided. It is also easier to implement than is shared memory for inter computer communication, But the main disadvantage is it can handle only small amounts ~of data. 2. Shared-Memory Model : In this, processes use shared memory creates and shared memory attaches system calls to create and gain access to regions of memory owned by other processes. Two or more Processes can exchange information by reading and ‘writing data in the shared areas. Shared memory allows ‘maximum speed and convenience of communication, since; it can be done at memory speeds when it takes place within a computer problems exist, however, in the areas of protection aitd synchronization between the re eng and ee weakness of these ogee two approaches (a) Message Passing Model : ‘Strengths: (Easier to implement (i) Best suited for smaller amount of data ‘Weakness: (@ Only suitable for the ex« data. — i ‘cation using message passing is slow @ Gommared memory Because ofthe time involved in connection setup. (b) Shared Memory Model: Strengths : Shared memory communication is faster the message passing model when the processes are ‘on the same machine. ‘Weakness : (Different processes need to ensuge that they are ‘not writing to the same location simultaneously. (ii) Processes that communicate using shared memory need to address problems of memory protection and synchronization. a’ QUs fat are the difference between user level threads and kernel level threads under what circumstances is one type better than the other? IRTU. 2016} change of small amount of Ans. Difference between user level threads and Kernel level threads : Yes, Kernel level and user level threads ai different, S.] User Level Threa No. — Kernel Leve)Thread 1. |User thread are Kernel threads are implemented by users.__|implemented by OS. - ]OS doesn't recognized [Kernel threads are user level threads. _| recognized by OS. 3. [Implementation of User |Implementation of threads is easy. Kernel thread is + lcomplicated. 4. |Context switch time is |Context switch time is less. more. 5. |Context switch requires [Hardware support is no hardware support. _|needed. 6. |ifone user level thread If one kernel thread perform blocking —_| perform blocking operation then entire | operation then another Process will be blocked. |thread can continue . [Example : Java thi = [Example Java Example : Wi EOSIN eases | scene gs seer Circumstances is one type better than the other : A user thread is more appropriate for low-l tasks, whereas a kernel thread is better for high poy tasks that should get high priority to system resources The benefits of executing tatks in modular treads instead of independent processes are us follows 1 Takes less time to create a new throsd than @ process: 3 bess time to terminate a thread than process 3 Less time to switch between two threads within the s. the same process share files, they can communicate with each ther without invoking the kemel, % Responsiveness = One tread may provide rapid Fesponse while other threads are blocked or sloveed down doing intensive calculations 6 Resource Sharing - By default threads share ‘Sommen code, data, and other resources, which allows multiple ‘tasks to be performed ‘simultaneously in a single address spate 7. ‘Sealability, ic. Utilization of multiprocessor xchitectures~A single threaded process can only fun on one CPU, no matter how many may be available, whereas the execution of a malt threaded application may be split amongst avaiable Processors, CoNLrE Switching in Processes : Refer 10 0.11 ‘Context Switching in Threads : Refer to 9.91 4 software that manages the computer hardware ead ‘provide an environment in which a user can execute ‘Programs in a convenient and efficient manner. ‘An operating system acts as an intermediary between the user of a computer and the computer hardware ag ‘shown in below fig. 1: Geert Sten} _______________66 79) ns pace wi Keepin tack of oh wing which i ok Operating Syren an n Resource Manager Phe concep ofthe opera nae a ia viding its uses with a convenient itt i in vew an sera eae “iw a the operating sytem shee to manage al the pcos ‘compen system. Modern computer cone of Drocessors, momoris, timers, disks, mice, metvork acc, printers mt wide vary of ther devices Inthe aermive view, he job ofthe operating esters es ‘0 provide foranordery an controle allocation of the Proceso, memories uid IO devices among he valone Programs competing fr them When » computer or network) has multiple wer, the need for managing and protecting the meso 10 devices and other resources is even pes sce hg Users migh otherwise interface wil one tootcr te addon, users often need to share nt ony hao ba information (les, database ete) an wel shor tiewof he operating sytem holds that ta primary tk to ecp tack of who in using which estore Grane FRsOure request, 0 acount for uage and fo eee Conflicting requess from diferent rosea nod Resource mangement (Sharing) resources in two nas Whena resouteistime multploce or users tke ume the resouree then ante only one CPU and mut it, the operating system Program, then her it has decision has to be One isto be printed next se op te kind of mltplexingis space mukiplexing. trated ofthe customer taking tums, each gets por of diigentte; For example, main memory is normally Givided up among several inning programs, sovachan? Gaube resident atthe same time (for example inorder meen ssing the CPU). Assuming ther is enough rae oto hold multiple programs tis more efficients {ol several programs in memory alone ratherthav gig $ne of them allo it, especially if it only needs vec Frstonof he tol, Ofcourse, hisrase issues offaine, rrr nt and soon and tis upto the operating system vy . me dice | opening system vesenitcn managen is typical ope rw eeratng Siam ae Virtual Machines ial manaycolgs ow operating rym an create the illusion that a prezass has ts one proces with its own (viral) memeny Of const, normaly, the moe has adda feat, sath nose al ond 4 fie em, ht ve roid byt bre have The vinualmachine appronch, on the cher hand, ft prestide nny siti funetiomality, ba eater pacrides fan interface that is identical to the underlaying bere hardware. Bach process is provided with « virtual) Copy of the underlying computer fig 2) jd tran o ao ‘Me-2: Sytem motels (a) Monta machine) tea! machine ‘The physical computer shares resources to create the virtal machines. CPU scheduling can share out the CPU to cteate the appearance that users have their own Processors. Spooling and a filesystem can provide vineat Sard renders and virtual line printers. A pormal user time, sharing terminal provides the function of the viriuel, ie operator's console. ([Link] difficulty with the viuabmachine spproach intelves disk systems. Suppose that the physical rachacy tas thre disk drives but wants to support seven sino machines, H cannot allocate a disk drive to exch virtesl

You might also like