System Software Computer Science and Engineering College of Engineering The Ohio State University Lecture 13
Road Map Lectures Administration Abstract machine characteristics Version control Software engineering Technical writing Lab 1 Forming Groups Requirements analysis Design Review Implementation Submission of documentation
System Software What is system software anyway? Answer: Software that supports the operation of the computer Often closely related to the architecture Allows developers to focus on the application without worrying about the low-level details of the machine
What and Why Examples Operating systems Device drivers Compilers, linkers/loaders, assemblers Motivation Software can often do a better job of managing the computer and optimizing performance People are expensive, computers are cheap
Layers of Abstraction Computer can be viewed at different levels of abstraction Each layer is a kind of virtual machine Each virtual machine corresponds to a language Bridges the human/computer gap Application Tools High-level Assembly ISA Microarchitecture Circuits
Computer Program Program: A collection of actions Written in a formal notation (language) Static (a piece of text, a file) Variations in language Imperative, functional, object-oriented, dynamically typed
Compiling Programs Program = Text file Contains easy-to-understand statements like "print", "if", "while", etc. But a computer can only execute machine instructions Instruction set architecture of the CPU A compiler translates the program (source code) into an executable (machine code) Recall "Bugs World" from CSE 2231 Examples: C, C++, Objective-C, Ada
Interpreting Programs An interpreter reads a program and executes it directly Advantages Platform independence Read-eval-print loop (aka REPL) Reflection Disadvantages Speed Later error detection (i.e., at run time) Examples: JavaScript, Python, Ruby
Combination of Both A language is not inherently compiled or interpreted A property of its implementation Sometimes a combination is used: Compile source code into an intermediate representation (byte code) Interpret the byte code Examples of combination: Java, C#
Java: Compile and Interpret program byte code MyProgram.java compiled MyProgram.class interpreted Java VM
Compile vs Interpret Compilation/interpretation is not fundamental to a language definition Can occur at all levels High-level or interpret compiler Assembly assembler Machine Language or interpret
Program vs Process Process: a program in execution Stateful (memory, registers) Current location of execution (PC) Variables have values (data section) Call stack Dynamic (changes over time) Instruction execution I/O interrupts (keyboard, touch, mouse, network, graphics ) Synchronization with other processes
Operating Systems How does a program become a process? Requires certain system resources (processor, memory, I/O, ) At any instant, there are many processes Multiple, concurrent users (stdlinux) Multiple, concurrent applications OS background tasks But there are a fixed set of resources Operating system handles resource management and process scheduling
Process Lifecycle
Challenges in Operating Systems Concurrency is fundamental Actors (processes/environment) are independent actors Concurrency is hard Nondeterminism Same inputs and initial conditions can result in different results Problems are hard to reproduce, debug Complex mental model: Impossible to think through all possible interleavings Synchronization is not familiar from sequential programming
Danger: Deadlock Example: Process A holds resource X, needs Y Process B holds resource Y, needs X Generally: a cycle in the resourceallocation graph
Danger: Starvation A process waits for a resource forever Example: Process A is waiting for resource X Two higher-priority processes alternate in using X, and A always loses out
Example A 2-way road squeezes down to one lane through a 4-mile tunnel Lane can not accommodate 2-way traffic No shoulder, pull-outs, turnarounds in tunnel Design a traffic protocol for the tunnel Cars at one end can not see the road at the other end of the tunnel Can use signs, clocks, traffic lights, flares, sextants, lunar calendar
Solutions?
Example: Dining Philosophers Set of philosophers, each of which is thinking, hungry, or eating Eating is finite, but may think forever Eating requires having forks, but forks are shared with neighbors Classically, 5 philosophers in a ring
Solutions?
Many More Examples Readers-writers Readers can share access to critical section, writers require exclusive access Bounded-buffer Producer putting things into buffer, consumer taking things out Producer has to wait if buffer is full, consumer has to wait if buffer is empty Sleeping barber, cigarette smokers, roller coaster, drinking philosophers
Responsibilities of OS Schedules processes Handles interrupts Manages real memory Manages virtual memory Large block of contiguous memory space Can be larger than physical memory File management File handles for open files, position marks Security Restrict what user-level process can do Prevent one user from interfering with another
Virtual Mem, Pages, Page Faults
Summary Compiling vs interpreting Program vs Process Operating systems: Challenges Operating systems: Responsibilities