Operating System Tutorial

Source: http://codex.cs.yale.edu/avi/os-book/os7/slide-dir/index.html

Outline
Introduction Process and Threads Deadlocks and Process Synchronization Scheduling Interrupts & System Calls Memory Management

. Operating system goals: Execute user programs and make solving user problems easier.What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. Use the computer hardware in an efficient manner. Make the computer system convenient to use.

Four Components of a Computer System .

only executable in kernel mode System call changes mode to kernel.Operating-System Operations Dual-mode operation allows OS to protect itself and other system components User mode and kernel mode Mode bit provided by hardware Provides ability to distinguish when system is running user code or kernel code Some instructions designated as privileged. return from call resets it to user .

Transition from User to Kernel Mode .

Process Concept Process a program in execution process execution must progress in sequential fashion A process includes: program counter stack data section .

Process Control Block (PCB) .

Process State Diagram .

CPU Switch From Process to Process .

Representation of Process Scheduling .

the system does no useful work while switching Time dependent on hardware support .Context Switch When CPU switches to another process. the system must save the state of the old process and load the saved state for the new process Context-switch time is overhead.

Cooperating Processes Independent process cannot affect or be affected by the execution of another process Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience .

producer process produces information that is consumed by a consumer process unbounded-buffer places no practical limit on the size of the buffer bounded-buffer assumes that there is a fixed buffer size .Producer-Consumer Problem Paradigm for cooperating processes.

they need to: establish a communication link between them exchange messages via send/receive .Interprocess Communication (IPC) Mechanism for processes to communicate and to synchronize their actions Message system – processes communicate with each other without resorting to shared variables IPC facility provides two operations: send(message) – message size fixed or variable receive(message) If P and Q wish to communicate.

Threads A flow of control in a process has access to entire process (incl. so low overheads All threads within a process share the same state and same memory space use different stack and can communicate with each other directly. other threads) potentially parallel execution minimal state. . because they share the same variables.

Single and Multithreaded Processes .

Benefits Responsiveness Resource Sharing Economy Utilization of MP Architectures .

Process vs Thread Process Address Space Stack Communication State Information Context Switch Overhead Not Shared Not Shared IPC Different Large Thread Shared Not Shared Direct Same Small .

Switches from waiting to ready 4. Terminates Scheduling under 1 and 4 is nonpreemptive All other scheduling is preemptive . and allocates the CPU to one of them CPU scheduling decisions may take place when a process: 1.CPU Scheduler Selects from among the processes in memory that are ready to execute. Switches from running to waiting state 2. Switches from running to ready state 3.

this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency – time it takes for the dispatcher to stop one process and start another running .Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler.

Scheduling Optimization Criteria Max CPU utilization Min turnaround time Min waiting time Few Algorithms First Come First Serve Shortest Job First Priority based Round Robin .

Deadlock: Bridge Crossing Example .

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. Mutual exclusion Hold and wait No preemption Circular wait .

. Allow the system to enter a deadlock state and then recover.Methods for Handling Deadlocks Ensure that the system will never enter a deadlock state.

Mutual Exclusion Hold and Wait Require process to request and be allocated all its resources before it begins execution or allow process to request resources only when the process has none No Preemption Circular Wait .Deadlock Prevention Restrain the ways request can be made.

Determines which type of interrupt has occurred: polling vectored interrupt system Separate segments of code determine what action should be taken for each type of interrupt .Interrupt Handling The operating system preserves the state of the CPU by storing registers and the program counter.

Interrupt Timeline .

. An operating system is interrupt driven. Interrupt architecture must save the address of the interrupted instruction.Common Functions of Interrupts Interrupt transfers control to the interrupt service routine generally. through the interrupt vector. Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt. A trap is a software-generated interrupt caused either by an error or a user request. which contains the addresses of all the service routines.

Sign up to vote on this title
UsefulNot useful