Download presentation
Presentation is loading. Please wait.
Published byRosalind Boyd Modified over 9 years ago
1
Silberschatz and Galvin 1999 7.1 Operating Systems Overview D. Manivannan Department of Computer Science University of Kentucky
2
Silberschatz and Galvin 1999 7.2 What is an Operating System? Resource Manager of a Computer Provides an user friendly environment
3
Silberschatz and Galvin 1999 7.3 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
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.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): while S 0 do no-op; S := S – 1; signal (S): S := S + 1; (A problem with this implementation is processes will “busy wait” wasting CPU cycles)
7
Silberschatz and Galvin 1999 7.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): if S >= 1 then S := 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
Silberschatz and Galvin 1999 7.8 Solution to Critical Section using Semaphores Shared variables –var mutex : semaphore –initially mutex = 1 Process P i repeat wait(mutex); critical section signal(mutex); remainder section until false;
9
Silberschatz and Galvin 1999 7.9 Semaphore as General Synchronization Tool Execute B in P j only after A is executed in P i Use semaphore flag initialized to 0 Code: P i P j Await(flag) signal(flag)B
10
Silberschatz and Galvin 1999 7.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 P 0 P 1 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
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.12 Classical Problems of Synchronization Bounded-Buffer Problem Readers and Writers Problem Dining-Philosophers Problem
13
Silberschatz and Galvin 1999 7.13 Bounded-Buffer Problem Shared data type item = … var buffer = … full, empty, mutex: semaphore; nextp, nextc: item; full :=0; empty := n; mutex :=1;
14
Silberschatz and Galvin 1999 7.14 Bounded-Buffer Problem (Cont.) Producer process repeat … produce an item in nextp … wait(empty); wait(mutex); … signal(mutex); signal(full); until false;
15
Silberschatz and Galvin 1999 7.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 … until false;
16
Silberschatz and Galvin 1999 7.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: var mutex, wrt: semaphore (=1); Shared Var readcount : integer (=0); Writer process wait(wrt); … writing is performed … signal(wrt);
17
Silberschatz and Galvin 1999 7.17 Readers-Writers Problem (Cont.) Reader process wait(mutex); readcount := readcount +1; if readcount = 1 then wait(wrt); signal(mutex); … reading is performed … wait(mutex); readcount := readcount – 1; if readcount = 0 then signal(wrt); signal(mutex):
18
Silberschatz and Galvin 1999 7.18 Dining-Philosophers Problem Shared data var chopstick: array [0..4] of semaphore; (=1 initially)
19
Silberschatz and Galvin 1999 7.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 … until false; Problem with this solution: deadlock and starvation
20
Silberschatz and Galvin 1999 7.20 High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes. type monitor-name = monitor variable declarations procedure entry P1 (…); begin … end; procedure entry P2(…); begin … end; procedure entry Pn (…); begin…end; begin initialization code end Monitors
21
Silberschatz and Galvin 1999 7.21 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 var x, 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. Monitors (Cont.)
22
Silberschatz and Galvin 1999 7.22 Schematic view of a monitor
23
Silberschatz and Galvin 1999 7.23 Monitor with condition variables
24
Silberschatz and Galvin 1999 7.24 type dining-philosophers = monitor var state : array [0..4] of :(thinking, hungry, eating); var self : array [0..4] of condition; procedure entry pickup (i: 0..4); begin state[i] := hungry, test (i); if state[i] eating then self[i]. wait, end; procedure entry putdown (i: 0..4); begin state[i] := thinking; test (i+4 mod 5); test (i+1 mod 5); end; Dining Philosophers Example
25
Silberschatz and Galvin 1999 7.25 procedure test(k: 0..4); begin if state[(k+4) mod 5] eating and state[k] = hungry and state[[k+1 mod 5] ] eating then begin state[k] := eating; self[k].signal; end; begin for i := 0 to 4 do state[i] := thinking; end. Dining Philosophers (Cont.)
26
Silberschatz and Galvin 1999 7.26 Philosopher i dining-philosophers.pickup(i) Start eating; dining-philosophers.putdown(i)
27
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.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
Silberschatz and Galvin 1999 7.32 Price per Megabyte of DRAM, From 1981 to 2004
33
Silberschatz and Galvin 1999 7.33 Price per Megabyte of Magnetic Hard Disk, From 1981 to 2004
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.