Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.

Similar presentations


Presentation on theme: "Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of."— Presentation transcript:

1 Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of new instructions and features above and beyond what is provided by the Instruction Set Architecture (ISA). New instructions added by the operating system are called system calls. Main functions delivered by typical operating systems –Virtual memory –Virtual instruction for I/O processing –Virtual instructions for parallel processing

2 Virtual memory What is a virtual memory? Virtual memory loosely describes a hierarchical storage system of at least two levels, which is managed by an operating system to appear to a user like a single large directly addressable main memory.

3 Virtual memory cont. Rationale for introduction of virtual memory –To free users from the need to carry out storage allocation –To make programs independent of the configuration and capacity of the memory systems used during their execution –To permit efficient sharing of memory space among different users (processes) and achieve the high access rates and low cost per bit that is possible with a memory hierarchy

4 Virtual I/O instructions Why virtual I/O instructions –Handling I/O operations at the ISA level is extremly tedious and complex –Virtual I/O instructions allow to operate on abstractions like files and directories –Virtual I/O instructions allow to implement necessary safety and security mechanisms

5 Virtual instructions for parallel processing Why virtual instructions for parallel processing? –many problems yield themselves to be efficiently processed by two or more processes running in parallel –parallel processing may be viewed as an answer to both technological and economical limitations connected with computing –in order for several processes to work together in parallel certain virtual instructions are needed

6 Virtual instructions for parallel processing Typical virtual instructions for parallel processing Process creation, termination, synchronization, communication, etc. Process vs Thread –Process, simply stated, is a program in execution, it is characterized by Separate program counter, CPU registers, address space for code and data –Thread (lightweight process) is characterized by Separate program counter, CPU registers, stack space Shared address space for code and data, OS resources like files, signals, etc.

7 Concurrent Execution vs Multitasking time Process 1 Process 2 Process 3 time Process 1 Process 2 Process 3

8 Scheduling – states of a process new ready running waiting terminated Admitted Interrupt I/O or event completion Scheduler dispatch I/O or event wait Exit

9 Scheduling criteria CPU utilization – ratio of in-use time to total observation time Throughput – number of processes completed per time unit Turnaround time – amount of time from a submission of a process for execution to its completion Waiting time – amount of time a process spends waiting for execution Response time – amount of time from issuing a request to observing a response

10 Scheduling policies –Non-preemptive First Come First Served Shortest Job First –Preemptive Round-Robin Priority-based –Multi-level queues Queue of different priorities with possibly different scheduling algorithm for each queue –Multi-level queues with feedback Possibility of process migration among queues on the basis of its execution characteristics

11 Problems connected with concurrent (multitasked) execution of processes (threads) Data corruption Determining if data can be corrupted by concurrent access from more than one process (thread), and if so, designing mechanisms to prevent it from happening (safety analysis). Deadlock Determining whether the application will be alive (liveness analysis). Safety analysis and liveness analysis form correctness analysis

12 Bernstein’s conditions 1.If process P i writes to memory location M i, no process P j can read memory location M i 2.If process P i reads from memory location M i, no process P j can write to memory location M i 3.If process P i writes to memory location M i, no P j can write to memory location M j

13 Problem of data corruption void *thread_function1( void *ptr ) { int i = 0; for(i = 0; i < 1000; i++) { X++; } pthread_exit(0); } void *thread_function2( void *ptr ) { int i = 0; for(i = 0; i < 1000; i++) { X++; } pthread_exit(0); } What will be a value of X after completion of the whole program?

14 Problem of data corruption We need to establish some mechanism to shield X from being accessed concurrently from the two processes (threads) –re-design the program –use synchronization mechanisms –use atomic instructions

15 Problem of deadlock "In concurrent systems, liveness means that if something is supposed to happen then eventually it will happen.... The word 'eventually'... means exactly that: within an unspecified but finite length of time.” M. Ben-Ari, Principles of Concurrent Programming

16 Problem of deadlock cont. Deadlock A deadlock, very simply, is a condition in which two or more threads wait for each other to release a shared resource before resuming their execution. Four conditions for deadlock –mutual exclusion – processes have exclusive control of resources –hold and wait – processes have some resources and wait for more –no preemption – resources cannot be removed from a process –circular wait – a circular chain of processes exists in which each process holds one or more resources requested by the next process in the chain

17 Illustration of the problem of deadlock with Resource Allocation Graphs (RAGs) Resource 1 Process 1 Resource 2 Process 2 Process 1 has acquired Resource 1 Process 2 has acquired Resource 2 Process 1 requests Resource 2 Process 2 requests Resource 1

18 Dealing with deadlock Deadlock prevention –one-shot algorithm, where you must acquire all resources or none –hierarchical algorithm, acquire resources in a preset order, acquire low priority resources before high priority ones Deadlock avoidance –Dijkstra's Banker Algorithm, assumes foreknowledge of all processes (useless in practice) Deadlock detection and recovery –deadlock occurs and then some processes are terminated and the mess is cleaned up (posthumous way)

19 Detecting deadlock Resource Allocation Graphs –For any state that a given process is in, it can be determined whether the system is deadlocked or not Computing invariants –Method of detecting possible deadlocks, which uses a set of statements that hold true, no matter what states the set of processes is in (Lectures of Prof. Węgrzyn) –Problem: the computation may not be effective. Analysis of deadlock scenario –It is decidable whether a scenario that is identified as a deadlock can be reached given a certain initial state of processes –Sometimes, much more efficient than a mechanical execution of an algorithm


Download ppt "Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of."

Similar presentations


Ads by Google