1 / 33

Operating Systems Overview

This overview of operating systems covers processes, process scheduling, CPU scheduling algorithms, process synchronization using semaphores, and classical synchronization problems. It provides a comprehensive understanding of key concepts in operating systems.

davidfisher
Download Presentation

Operating Systems Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems Overview D. Manivannan Department of Computer Science University of Kentucky

  2. What is an Operating System? • Resource Manager of a Computer • Provides an user friendly environment

  3. Processes • Processes • States of process, process control block, • Scheduling of processes • Long term scheduler, short term scheduler, medium-term scheduler (swapping) • Degree of multiprogramming • Context switch • Operation on processes • Process creation, fork, execlp, execvp system calls in UNIX • Threads • Difference between a process and a thread

  4. Process Scheduling • What is CPU scheduling? • Short term scheduler • Preemptive scheduling, • Scheduling criteria • CPU utilization, throughput, turnaround time, waiting time, response time • Scheduling algorithms • FCFS, SJF, Priority scheduling, Round-robin scheduling • Multilevel queue scheduling, multilevel feed back queue scheduling • Real-time scheduling • How are various scheduling algorithms evaluated • Deterministic modeling, queuing models, simulations, implementations

  5. Process Synchronization • The critical section problem • Synchronization mechanisms • Hardware instruction support (e.g. test and set instruction, swap instruction). • Semaphores • Binary semaphores, counting semaphores • Should know how to use semaphores to solve synchronization problems • Problems with using semaphores • Deadlock, starvation, wrong use of semaphores • Monitors • Should know how to use monitors for solving synchronization problems • Classical synchronization problems • The bounded buffer problem • Readers writers problem • Dining philosophers problem

  6. Process Synchronization - Semaphores • Semaphores serve as a synchronization tool, usually supported by the operating system. • Semaphore S – integer variable • S can only be accessed via two indivisible (atomic) operations wait (S): whileS 0 dono-op;S := S– 1; signal (S): S := S + 1; (A problem with this implementation is processes will “busy wait” wasting CPU cycles)

  7. Usual Implementation of semaphores Each semaphore is an integer variable; it also has a queue associated with it. (this implementation prevents “busy wait”) wait (S): ifS >= 1 thenS := S - 1; else block the process on the semaphore queue signal (S): if some processes are blocked in the semaphore queue then unblock a process else S := S + 1;

  8. Solution to Critical Section using Semaphores • Shared variables • varmutex : semaphore • initially mutex = 1 • Process Pi repeat wait(mutex); critical section signal(mutex); remainder section untilfalse;

  9. Semaphore as General Synchronization Tool • Execute B in Pj only after A is executed in Pi • Use semaphore flag initialized to 0 • Code: Pi Pj   Await(flag) signal(flag) B

  10. What Problems can Arise When Semaphores are Used : Deadlock and Starvation • Deadlock – two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. • Let S and Q be two semaphores initialized to 1 P0P1 wait(S); wait(Q); wait(Q); wait(S);   signal(S); signal(Q); signal(Q) signal(S); • Starvation – indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended.

  11. Two Types of Semaphores • Counting semaphore – integer value can range over an unrestricted domain. • Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement. • Can implement a counting semaphore S using binary semaphores.

  12. Classical Problems of Synchronization • Bounded-Buffer Problem • Readers and Writers Problem • Dining-Philosophers Problem

  13. Bounded-Buffer Problem • Shared data typeitem = … varbuffer = … full, empty, mutex: semaphore; nextp, nextc: item; full :=0; empty := n; mutex :=1;

  14. Bounded-Buffer Problem (Cont.) • Producer process repeat … produce an item in nextp … wait(empty); wait(mutex); … signal(mutex); signal(full); untilfalse;

  15. Bounded-Buffer Problem (Cont.) • Consumer process repeat wait(full) wait(mutex); … remove an item from buffer to nextc … signal(mutex); signal(empty); … consume the item in nextc … untilfalse;

  16. Readers-Writers Problem • Readers Writers Problem: Writers have exclusive access to shared data; Readers can access shared data simultaneously. • A solution to this problem using semaphores: varmutex, wrt: semaphore (=1); Shared Varreadcount : integer (=0); • Writer process wait(wrt); … writing is performed … signal(wrt);

  17. Readers-Writers Problem (Cont.) • Reader process wait(mutex); readcount := readcount +1; ifreadcount = 1 thenwait(wrt); signal(mutex); … reading is performed … wait(mutex); readcount := readcount – 1; ifreadcount = 0 thensignal(wrt); signal(mutex):

  18. Dining-Philosophers Problem • Shared data varchopstick: array [0..4] ofsemaphore; (=1 initially)

  19. Dining-Philosophers Problem (Cont.) • Philosopher i: repeat wait(chopstick[i]) wait(chopstick[(i+1) mod 5]) … eat … signal(chopstick[i]); signal(chopstick[(i+1) mod 5]); … think … untilfalse; Problem with this solution: deadlock and starvation

  20. Monitors • High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes. typemonitor-name = monitor variable declarations procedure entryP1 (…); begin … end; procedureentryP2(…); begin … end;  procedure entryPn (…); begin…end; begin initialization code end

  21. Monitors (Cont.) • Only one process can be active inside the monitor. • To allow a process to wait within the monitor, a condition variable must be declared, as varx, y: condition • Condition variable can only be used with the operations wait and signal. • The operation x.wait;means that the process invoking this operation is suspended until another process invokes x.signal; Wait operation releases the monitor. • The x.signal operation resumes exactly one suspended process. If no process is suspended, then the signal operation has no effect.

  22. Schematic view of a monitor

  23. Monitor with condition variables

  24. Dining Philosophers Example typedining-philosophers = monitor varstate : array [0..4] of :(thinking, hungry, eating); varself : array [0..4] ofcondition; procedure entrypickup (i: 0..4); begin state[i] := hungry, test (i); ifstate[i] eating thenself[i]. wait, end; procedure entryputdown (i: 0..4); begin state[i] := thinking; test (i+4 mod 5); test (i+1 mod 5); end;

  25. Dining Philosophers (Cont.) proceduretest(k: 0..4); begin ifstate[(k+4) mod 5]  eating andstate[k] = hungry andstate[[k+1 mod 5] ]  eating then begin state[k] := eating; self[k].signal; end; end; begin fori := 0 to 4 do state[i] := thinking; end.

  26. Philosopher i dining-philosophers.pickup(i) Start eating; dining-philosophers.putdown(i)

  27. Memory Management • Overlays, physical and logical address space • Swapping • Memory allocation for processes • Contiguous allocation – Advantages Disadvantages : external and internal fragmentation • Paged allocation • Address translation under paged allocation • Page table implementation • Associative registers, Translation look aside buffers • Effective access time calculation • Two level paging scheme • Inverted page table architecture • Sharing pages between processes – adv. Disadv. • Segmentation-based allocation • Address translation under segmentation based allocation

  28. Virtual Memory • What is virtual memory? • Demand paging (an implementation of virtual memory) • Page faults, effective access time calculation • Page replacement algorithms • FIFO, Optimal algorithm, LRU, Additional reference bit algorithm, Second chance algorithm – comparison of these algorithms • Counting algorithms • LFU (least frequently used ) • MFU (most frequently used) • Allocation of frames • Issues that need to be taken into consideration for • Different allocation schemes • Fixed, priority-based, equal, proportionate • Thrashing • What is thrashing? Causes for thrashing • Working set model to solve the problem of thrashing • How can program structure contribute to thrashing?

  29. File System Interface • File structures • File attributes, operation, types, access methods • Device directory • Different directory structures • Single level • Two level • Tree Structured • Acyclic graph structured • General graph structured • File access protection

  30. File System Implementation • File system • Disk space allocation • Contiguous, linked, indirect, • Mapping under each allocation • UNIX allocation scheme • Free Space management • Bit vector, linked list approach, grouping, counting

  31. Secondary and tertiary storage • Disk Structure • Cylinders, tracks, sector(block) • Disk Scheduling • Goal of a good scheduling algorithm • Various scheduling algorithms • FCFS, SSTF, SCAN, C-SCAN, C-LOOK • Performance of these algorithms • Reliability • RAID • Tertiary storage • Removable disks, WORM disks, Tapes, • Hierarchical storage management

  32. Price per Megabyte of DRAM, From 1981 to 2004

  33. Price per Megabyte of Magnetic Hard Disk, From 1981 to 2004

More Related