CS 1550 Introduction to Operating Systems Prof Ahmed

  • Slides: 33
Download presentation
CS 1550: Introduction to Operating Systems Prof. Ahmed Amer Chapter 1

CS 1550: Introduction to Operating Systems Prof. Ahmed Amer Chapter 1

Class outline n n Introduction, concepts, review & historical perspective Processes n n n

Class outline n n Introduction, concepts, review & historical perspective Processes n n n n Synchronization Scheduling Deadlock Memory management, address translation, and virtual memory Operating system management of I/O File systems Security & protection Distributed systems (as time permits) CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 2

Overview: Chapter 1 n n n What is an operating system, anyway? Operating systems

Overview: Chapter 1 n n n What is an operating system, anyway? Operating systems history The zoo of modern operating systems Review of computer hardware Operating system concepts Operating system structure n n User interface to the operating system Anatomy of a system call CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 3

What is an operating system? n A program that runs on the “raw” hardware

What is an operating system? n A program that runs on the “raw” hardware and supports n n n Abstracts and standardizes the interface to the user across different types of hardware n n Virtual machine hides the messy details which must be performed Manages the hardware resources n n n Resource Abstraction Resource Sharing Each program gets time with the resource Each program gets space on the resource May have potentially conflicting goals: n n Use hardware efficiently Give maximum performance to each user CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 4

Operating system timeline n First generation: 1945 – 1955 n n n Second generation:

Operating system timeline n First generation: 1945 – 1955 n n n Second generation: 1955 – 1965 n n Integrated circuits Multiprogramming Fourth generation: 1980 – present n n n Transistors Batch systems Third generation: 1965 – 1980 n n Vacuum tubes Plug boards Large scale integration Personal computers Next generation: ? ? ? n n Systems connected by high-speed networks? Wide area resource management? CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 5

First generation: direct input n Run one job at a time n n Problem:

First generation: direct input n Run one job at a time n n Problem: lots of wasted computer time! n n n Enter it into the computer (might require rewiring!) Run it Record the results Computer was idle during first and last steps Computers were very expensive! Goal: make better use of an expensive commodity: computer time CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 6

Second generation: batch systems n n n Bring cards to 1401 Read cards onto

Second generation: batch systems n n n Bring cards to 1401 Read cards onto input tape Put input tape on 7094 Perform the computation, writing results to output tape Put output tape on 1401, which prints output CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 7

Structure of a typical 2 nd generation job Data for program FORTRAN program $END

Structure of a typical 2 nd generation job Data for program FORTRAN program $END $RUN $LOAD $FORTRAN $JOB, 10, 6610802, ETHAN MILLER CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 8

Spooling n n Original batch systems used tape drives Later batch systems used disks

Spooling n n Original batch systems used tape drives Later batch systems used disks for buffering n n n Operator read cards onto disk attached to the computer Computer read jobs from disk Computer wrote job results to disk Operator directed that job results be printed from disk Disks enabled simultaneous peripheral operation online (spooling) n n n Computer overlapped I/O of one job with execution of another Better utilization of the expensive CPU Still only one job active at any given time CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 9

Third generation: multiprogramming n Multiple jobs in memory n Memory partitions Job 3 n

Third generation: multiprogramming n Multiple jobs in memory n Memory partitions Job 3 n Job 2 n Job 1 n Operating system protected from each job as well Resources (time, hardware) split between jobs Still not interactive n Operating system CS 1550, cs. pitt. edu (originaly modified by Ethan Protected from one another n n User submits job Computer runs it User gets results minutes (hours, days) later Chapter 1 10

Timesharing n Multiprogramming allowed several jobs to be active at one time n n

Timesharing n Multiprogramming allowed several jobs to be active at one time n n n Initially used for batch systems Cheaper hardware terminals -> interactive use Computer use got much cheaper and easier n n No more “priesthood” Quick turnaround meant quick fixes for problems CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 11

Types of modern operating systems Mainframe operating systems: MVS n Server operating systems: Free.

Types of modern operating systems Mainframe operating systems: MVS n Server operating systems: Free. BSD, Solaris n Multiprocessor operating systems: Cellular IRIX n Personal computer operating systems: Windows, Unix n Real-time operating systems: Vx. Works n Embedded operating systems n Smart card operating systems Þ Some operating systems can fit into more than one category n CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 12

Components of a simple PC Outside world Video controller CPU Memory CS 1550, cs.

Components of a simple PC Outside world Video controller CPU Memory CS 1550, cs. pitt. edu (originaly modified by Ethan Hard drive controller USB controller Network controller Computer internals (inside the “box”) Chapter 1 13

CPU internals Fetch unit Decode unit CS 1550, cs. pitt. edu (originaly modified by

CPU internals Fetch unit Decode unit CS 1550, cs. pitt. edu (originaly modified by Ethan Decode unit Execute unit Buffer Fetch unit Pipelined CPU Execute unit Decode unit Execute unit Superscalar CPU Chapter 1 14

Storage pyramid Capacity Better Access latency < 1 KB Registers 1 ns 1 MB

Storage pyramid Capacity Better Access latency < 1 KB Registers 1 ns 1 MB Cache (SRAM) 2– 5 ns 256 MB Main memory (DRAM) 50 ns 40 GB Magnetic disk 5 ms > 1 TB Magnetic tape 50 sec n Goal: really large memory with very low latency n n n Better Latencies are smaller at the top of the hierarchy Capacities are larger at the bottom of the hierarchy Solution: move data between levels to create illusion of large memory with low latency CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 15

Disk drive structure n Data stored on surfaces n n n Up to two

Disk drive structure n Data stored on surfaces n n n Up to two surfaces per platter One or more platters per disk Data in concentric tracks n Tracks broken into sectors n n n 256 B-1 KB per sector Cylinder: corresponding tracks on all surfaces Data read and written by heads n n Actuator moves heads Heads move in unison head sector platter track cylinder surfaces spindle CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 actuator 16

Memory Address 0 x 2 ffff 0 x 2 b 000 0 x 27

Memory Address 0 x 2 ffff 0 x 2 b 000 0 x 27 fff 0 x 23000 Address User program and data 0 x 1 dfff Limit 0 x 2 ffff 0 x 2 d 000 User data 0 x 2 bfff 0 x 29000 User data 0 x 24 fff Base 0 x 23000 Base 1 Operating system 0 n Limit 1 0 x 1 dfff Operating system n User program Limit 2 Base 2 0 Single base/limit pair: set for each process Two base/limit registers: one for program, one for data CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 17

Anatomy of a device request 3 CPU 1 n 5 Interrupt controller 6 1:

Anatomy of a device request 3 CPU 1 n 5 Interrupt controller 6 1: Interrupt Disk controller 4 Operating system Interrupt handler Left: sequence as seen by hardware n n 2 Instructionn+1 3: Return 2: Process interrupt Request sent to controller, then to disk Disk responds, signals disk controller which tells interrupt controller Interrupt controller notifies CPU Right: interrupt handling (software point of view) CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 18

Operating systems concepts n n n Many of these should be familiar to Unix

Operating systems concepts n n n Many of these should be familiar to Unix users… Processes (and trees of processes) Deadlock File systems & directory trees Pipes We’ll cover all of these in more depth later on, but it’s useful to have some basic definitions now CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 19

Processes n Process: program in execution n A n B C n D n

Processes n Process: program in execution n A n B C n D n OS keeps track of all processes in a process table Processes can create other processes n E F G n n CS 1550, cs. pitt. edu (originaly modified by Ethan Address space (memory) the program can use State (registers, including program counter & stack pointer) Process tree tracks these relationships A is the root of the tree A created three child processes: B, C, and D C created two child processes: E and F D created one child process: G Chapter 1 20

Inside a (Unix) process n 0 x 7 fffffff Stack Processes have three segments

Inside a (Unix) process n 0 x 7 fffffff Stack Processes have three segments n n Text: program code Data: program data n n n Data n 0 CS 1550, cs. pitt. edu (originaly modified by Ethan Automatic variables Procedure call information Address space growth n Text Stack n n Statically declared variables Areas allocated by malloc() or new n n Text: doesn’t grow Data: grows “up” Stack: grows “down” Chapter 1 21

Deadlock Potential deadlock CS 1550, cs. pitt. edu (originaly modified by Ethan Actual deadlock

Deadlock Potential deadlock CS 1550, cs. pitt. edu (originaly modified by Ethan Actual deadlock Chapter 1 22

Hierarchical file systems Root directory cse bin faculty ls ps cp grads csh elm

Hierarchical file systems Root directory cse bin faculty ls ps cp grads csh elm classes stuff CS 1550, cs. pitt. edu (originaly modified by Ethan sbrandt kag amer 4 research stuff Chapter 1 23

Interprocess communication n n Processes want to exchange information with each other Many ways

Interprocess communication n n Processes want to exchange information with each other Many ways to do this, including n n Network Pipe (special file): A writes into pipe, and B reads from it A CS 1550, cs. pitt. edu (originaly modified by Ethan B Chapter 1 24

System calls n Programs want the OS to perform a service n n Access

System calls n Programs want the OS to perform a service n n Access a file Create a process Others… Accomplished by system call n n Program passes relevant information to OS OS performs the service if n n n The OS is able to do so The service is permitted for this program at this time OS checks information passed to make sure it’s OK n Don’t want programs reading data into other programs’ memory! CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 25

Making a system call 0 xffff Library (read call) 4 Kernel space (OS) 0

Making a system call 0 xffff Library (read call) 4 Kernel space (OS) 0 n Increment SP Call read 1 Push arguments Dispatch n 8 2 5 CS 1550, cs. pitt. edu (originaly modified by Ethan 9 7 n n 6 Sys call handler System call: read(fd, buffer, length) n Return to caller Trap to kernel 3 Trap code in register User space n Program pushes arguments, calls library Library sets up trap, calls OS OS handles system call Control returns to library Library returns to user program User code Chapter 1 26

System calls for files & directories Call Description fd = open(name, how) Open a

System calls for files & directories Call Description fd = open(name, how) Open a file for reading and/or writing s = close(fd) Close an open file n = read(fd, buffer, size) Read data from a file into a buffer n = write(fd, buffer, size) Write data from a buffer into a file s = lseek(fd, offset, whence) Move the “current” pointer for a file s = stat(name, &buffer) Get a file’s status information (in buffer) s = mkdir(name, mode) Create a new directory s = rmdir(name) Remove a directory (must be empty) s = link(name 1, name 2) Create a new entry (name 2) that points to the same object as name 1 Remove name as a link to an object (deletes the object if name was the only link to it) s = unlink(name) CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 27

More system calls Call Description pid = fork() Create a child process identical to

More system calls Call Description pid = fork() Create a child process identical to the parent pid=waitpid(pid, &statloc, options) Wait for a child to terminate s = execve(name, argv, environp) Replace a process’ core image exit(status) Terminate process execution and return status s = chdir(dirname) Change the working directory s = chmod(name, mode) Change a file’s protection bits s = kill(pid, signal) Send a signal to a process seconds = time(&seconds) Get the elapsed time since 1 Jan 1970 CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 28

A simple shell while (TRUE) { /* repeat forever */ type_prompt( ); /* display

A simple shell while (TRUE) { /* repeat forever */ type_prompt( ); /* display prompt */ read_command (command, parameters) /* input from terminal */ if (fork() != 0) { /* fork off child process */ /* Parent code */ waitpid( -1, &status, 0); /* wait for child to exit */ } else { /* Child code */ execve (command, parameters, 0); /* execute command */ } } CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 29

Monolithic OS structure Main procedure Service routines Utility routines CS 1550, cs. pitt. edu

Monolithic OS structure Main procedure Service routines Utility routines CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 30

Virtual machines App 1 App 2 App 3 System calls I/O instructions Calls to

Virtual machines App 1 App 2 App 3 System calls I/O instructions Calls to simulate I/O “Real” I/O instructions n n Free. BSD VMware Linux Bare hardware Allows users to run any x 86 -based OS on top of Linux or NT “Guest” OS can crash without harming underlying OS n n Windows NT First widely used in VM/370 with CMS Available today in VMware n n Linux Only virtual machine fails—rest of underlying OS is fine “Guest” OS can even use raw hardware n Virtual machine keeps things separated CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 31

Microkernels (client-server) Client process Process server Terminal server … File server Memory server Microkernel

Microkernels (client-server) Client process Process server Terminal server … File server Memory server Microkernel n Kernel mode Processes (clients and OS servers) don’t share memory n n n User mode Communication via message-passing Separation reduces risk of “byzantine” failures Examples include Mach CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 32

Metric units Number Exp. Prefix Exp. Number Prefix 10 -3 0. 001 milli 103

Metric units Number Exp. Prefix Exp. Number Prefix 10 -3 0. 001 milli 103 1, 000 10 -6 0. 000001 micro 106 1, 000 10 -9 0. 00001 nano 109 1, 000, 000 Giga 10 -12 0. 0000001 pico 1012 1, 000, 000 Tera 10 -15 0. 00000001 femto 1015 1, 000, 000 Peta 10 -18 0. 0000000001 atto 1018 1, 000, 000 Exa CS 1550, cs. pitt. edu (originaly modified by Ethan Chapter 1 Kilo Mega 33