330 likes | 346 Views
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.
E N D
Operating Systems Overview D. Manivannan Department of Computer Science University of Kentucky
What is an Operating System? • Resource Manager of a Computer • Provides an user friendly environment
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
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
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
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)
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;
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;
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
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.
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.
Classical Problems of Synchronization • Bounded-Buffer Problem • Readers and Writers Problem • Dining-Philosophers Problem
Bounded-Buffer Problem • Shared data typeitem = … varbuffer = … full, empty, mutex: semaphore; nextp, nextc: item; full :=0; empty := n; mutex :=1;
Bounded-Buffer Problem (Cont.) • Producer process repeat … produce an item in nextp … wait(empty); wait(mutex); … signal(mutex); signal(full); untilfalse;
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;
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);
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):
Dining-Philosophers Problem • Shared data varchopstick: array [0..4] ofsemaphore; (=1 initially)
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
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
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.
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;
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.
Philosopher i dining-philosophers.pickup(i) Start eating; dining-philosophers.putdown(i)
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
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?
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
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
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